private static void ProcessControls(StrategyPanel_t panel, WpfControlRenderer renderer) { ControlCollection controls = panel.Controls; if (controls == null || controls.Count == 0) { return; } foreach (var control in controls) { renderer.ProcessControl(control); } }
public static void Render(Strategy_t strategy, XmlWriter writer, WpfComboBoxSizer sizer) { if (strategy.StrategyLayout == null) { throw ThrowHelper.New <RenderingException>(ExceptionContext, ErrorMessages.NoStrategyLayoutSupplied); } StrategyPanel_t rootPanel = strategy.StrategyLayout.StrategyPanel; if (rootPanel == null) { throw ThrowHelper.New <RenderingException>(ExceptionContext, ErrorMessages.NoStrategyPanelsInStrategy); } WpfXmlWriter wpfWriter = new WpfXmlWriter(writer); // TODO: Move this somewhere better WpfControlRenderer controlRenderer = new WpfControlRenderer(wpfWriter, sizer); // TODO: Move this elsewhere CompositionContainer defaultContainer = new CompositionContainer(new TypeCatalog(_defaultRenderers)); if (!string.IsNullOrEmpty(CustomControlRenderer)) { string applicationDirectory = (from assembly in System.AppDomain.CurrentDomain.GetAssemblies() where assembly.CodeBase.EndsWith(".exe") select System.IO.Path.GetDirectoryName(assembly.CodeBase.Replace("file:///", ""))).FirstOrDefault(); string customControlRendererPath = Path.Combine(applicationDirectory, CustomControlRenderer); AssemblyCatalog overridesCatalog = new AssemblyCatalog(customControlRendererPath); CompositionContainer aggregateContainer = new CompositionContainer(overridesCatalog, defaultContainer); aggregateContainer.ComposeParts(controlRenderer); } else { defaultContainer.ComposeParts(controlRenderer); } int depth = 0; ProcessPanel(rootPanel, wpfWriter, controlRenderer, -1, ref depth); }
private static void ProcessPanel(StrategyPanel_t panel, WpfXmlWriter writer, WpfControlRenderer controlRenderer, int rowOrColumn, ref int depth) { depth++; bool isVertical = (panel.Orientation == Orientation_t.Vertical); using (writer.New(DefaultNamespaceProvider.Atdl4netNamespace, "StrategyPanelFrame", DefaultNamespaceProvider.Atdl4netNamespaceUri)) { writer.WriteAttribute(WpfXmlWriterAttribute.Padding, "1"); writer.WriteAttribute(WpfXmlWriterAttribute.Margin, "1"); WritePanelAttributes(writer, panel); if (rowOrColumn == -1) { foreach (KeyValuePair <string, string> ns in controlRenderer.NamespaceProvider.CustomNamespaces) { writer.WriteNamespaceAttribute(ns.Key, ns.Value); } } else { writer.WriteAttribute((panel as IParentable <StrategyPanel_t>).Parent.Orientation == Orientation_t.Vertical ? WpfXmlWriterAttribute.GridRow : WpfXmlWriterAttribute.GridColumn, rowOrColumn.ToString()); } bool containsControls = (panel.Controls.Count > 0); // For grids containing a horizontal arrangement of controls, we add an empty column so we can set its width to "*" int childCount = containsControls ? panel.Controls.Count + (isVertical ? 0 : 1) : panel.StrategyPanels.Count; using (writer.New(WpfXmlWriterTag.Grid)) { if (depth == 1) { writer.WriteAttribute(WpfXmlWriterAttribute.DataContext, AtdlDataContext); } using (writer.New(WpfXmlWriterTag.GridRowDefinitions)) { int rowCount = isVertical ? childCount : 1; for (int n = 0; n < rowCount; n++) { using (writer.New(WpfXmlWriterTag.RowDefinition)) writer.WriteAttribute(WpfXmlWriterAttribute.Height, "Auto"); } } using (writer.New(WpfXmlWriterTag.GridColumnDefinitions)) { // Special treatment for vertical panels that contain controls - put in two columns, one for the label and // one for the control itself. int columnCount = isVertical ? (containsControls ? 2 : 1) : childCount; for (int n = 0; n < columnCount; n++) { using (writer.New(WpfXmlWriterTag.ColumnDefinition)) { if (containsControls) { writer.WriteAttribute(WpfXmlWriterAttribute.Width, (n < childCount - 1) ? "Auto" : "*"); } } } } // Note that a StrategyPanel_t can either contain other strategy panels, or controls but NOT BOTH. if (panel.StrategyPanels != null && panel.StrategyPanels.Count > 0) { int thisRowOrColumn = 0; foreach (StrategyPanel_t childPanel in panel.StrategyPanels) { ProcessPanel(childPanel, writer, controlRenderer, thisRowOrColumn, ref depth); thisRowOrColumn++; } } else { ProcessControls(panel, controlRenderer); // For horizontal strategy panels, put a dummy rectangle in the last column to trick // WPF to sizing the other columns to their control size. if (panel.Orientation == Orientation_t.Horizontal) { using (writer.New(WpfXmlWriterTag.Rectangle)) { writer.WriteAttribute(WpfXmlWriterAttribute.GridColumn, panel.Controls.Count.ToString()); } } } } } }