Exemple #1
0
        /// <summary>
        /// Add any bindings between the row and the DisplayContainer hosted in that row.
        /// </summary>
        private static void AddContainerRowDefinitionBindings(CollapsibleRowDefinition rowDefinitionForContainer, DisplayContainer displayContainer)
        {
            var isCollapsedBinding = new Binding()
            {
                Source = displayContainer,
                Path   = new PropertyPath(nameof(displayContainer.IsContentCollapsed))
            };

            BindingOperations.SetBinding(rowDefinitionForContainer, CollapsibleRowDefinition.IsCollapsedProperty, isCollapsedBinding);
        }
Exemple #2
0
        private void PopulateGrid()
        {
            this.ResetGrid();

            var activeContainers = this.DisplayContainers.Where(c => c.Visibility == Visibility.Visible).ToList();

            for (int index = 0; index < activeContainers.Count; index++)
            {
                var displayContainer = activeContainers[index];

                // Add a splitter between containers only after the first row.
                if (index != 0)
                {
                    var rowDefinitionForSplitter = new RowDefinition()
                    {
                        Height = new GridLength(1, GridUnitType.Auto)
                    };
                    this.grid.RowDefinitions.Add(rowDefinitionForSplitter);

                    var gridSplitter = new GridSplitter()
                    {
                        Style = (Style)InstrumentPanelResources.Instance["GridSplitterStyle"], Height = (double)InstrumentPanelResources.Instance["DisplayContainerSplitterHeight"]
                    };
                    Grid.SetRow(gridSplitter, this.grid.RowDefinitions.Count - 1);
                    this.grid.Children.Add(gridSplitter);

                    var previousContainer = activeContainers[index - 1];
                    AddGridSplitterBindings(gridSplitter, previousContainer, displayContainer);
                }

                var rowDefinitionForContainer = new CollapsibleRowDefinition()
                {
                    Height                = new GridLength(displayContainer.PreferredProportion, GridUnitType.Star),
                    ExpandedHeight        = new GridLength(displayContainer.PreferredProportion, GridUnitType.Star),
                    CollapsedHeight       = GridLength.Auto,
                    MinimumExpandedHeight = displayContainer.MinimumExpandedHeight,
                };

                AddContainerRowDefinitionBindings(rowDefinitionForContainer, displayContainer);

                this.grid.RowDefinitions.Add(rowDefinitionForContainer);
                Grid.SetRow(displayContainer, this.grid.RowDefinitions.Count - 1);
            }

            this.AddRowDefinitionPropertyChangedListeners();

            // Add a row at the end for hidden containers. We keep the hidden containers in the Grid to preserve the Bindings.
            var rowDefinitionForHiddenContainers = new RowDefinition()
            {
                Height = GridLength.Auto
            };

            this.grid.RowDefinitions.Add(rowDefinitionForHiddenContainers);

            var hiddenRowIndex   = this.grid.RowDefinitions.IndexOf(rowDefinitionForHiddenContainers);
            var hiddenContainers = this.DisplayContainers.Where(c => c.Visibility != Visibility.Visible).ToList();

            foreach (var container in hiddenContainers)
            {
                Grid.SetRow(container, hiddenRowIndex);
            }
        }