コード例 #1
0
ファイル: PropertyGrid.cs プロジェクト: janfokke/Myra
            public SubGrid(PropertyGrid parent, object value, string header, string category, Record parentProperty)
            {
                InternalChild = new Grid
                {
                    ColumnSpacing = 4,
                    RowSpacing    = 4
                };

                InternalChild.ColumnsProportions.Add(new Proportion(ProportionType.Auto));
                InternalChild.ColumnsProportions.Add(new Proportion(ProportionType.Fill));
                InternalChild.RowsProportions.Add(new Proportion(ProportionType.Auto));
                InternalChild.RowsProportions.Add(new Proportion(ProportionType.Auto));

                _propertyGrid = new PropertyGrid(parent.PropertyGridStyle, category, parentProperty, parent)
                {
                    Object              = value,
                    Visible             = false,
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    GridColumn          = 1,
                    GridRow             = 1
                };

                // Mark
                _mark = new ImageButton(null)
                {
                    Toggleable          = true,
                    HorizontalAlignment = HorizontalAlignment.Left,
                    VerticalAlignment   = VerticalAlignment.Center
                };
                _mark.ApplyImageButtonStyle(parent.PropertyGridStyle.MarkStyle);

                InternalChild.Widgets.Add(_mark);

                _mark.PressedChanged += (sender, args) =>
                {
                    if (_mark.IsPressed)
                    {
                        _propertyGrid.Visible = true;
                        parent._expandedCategories.Add(category);
                    }
                    else
                    {
                        _propertyGrid.Visible = false;
                        parent._expandedCategories.Remove(category);
                    }
                };

                var expanded = true;

                if (parentProperty != null && parentProperty.FindAttribute <DesignerFoldedAttribute>() != null)
                {
                    expanded = false;
                }

                if (expanded)
                {
                    _mark.IsPressed = true;
                }

                var label = new Label(null)
                {
                    Text       = header,
                    GridColumn = 1
                };

                label.ApplyLabelStyle(parent.PropertyGridStyle.LabelStyle);

                InternalChild.Widgets.Add(label);
                InternalChild.Widgets.Add(_propertyGrid);

                HorizontalAlignment = HorizontalAlignment.Stretch;
                VerticalAlignment   = VerticalAlignment.Stretch;
            }