Пример #1
0
 private void PropertyGrid_PropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     if (_editors.ContainsKey(e.PropertyName))
     {
         ValueEditorBase editor = _editors[e.PropertyName];
         editor.Item.Value = editor.Item.PropertyInfo.GetValue(editor.Item.Instance, null);
         editor.OnValueChanged(editor.Item.Value);
     }
 }
Пример #2
0
        private void CreateItem()
        {
            if (_categories.Count > 0)
            {
                int rowIndex = 0;
                PropertyGroupItem groupItem = null;
                Line gridLine            = null;
                PropertyGridLabel label  = null;
                ValueEditorBase   editor = null;
                foreach (KeyValuePair <string, List <PropertyItem> > keyValuePair in _categories)
                {
                    if (null != gridLine)
                    {
                        _mainGrid.Children.Remove(gridLine);
                    }
                    rowIndex          = _mainGrid.RowDefinitions.Count;
                    groupItem         = new PropertyGroupItem();
                    groupItem.Content = keyValuePair.Key;
                    Grid.SetRow(groupItem, rowIndex);
                    Grid.SetColumnSpan(groupItem, 3);
                    _mainGrid.Children.Add(groupItem);
                    _mainGrid.RowDefinitions.Add(new RowDefinition()
                    {
                        Height = new GridLength(1d, GridUnitType.Auto)
                    });
                    foreach (PropertyItem item in keyValuePair.Value)
                    {
                        rowIndex = _mainGrid.RowDefinitions.Count;
                        gridLine = CreateHorizontalGridLine(rowIndex, groupItem.Background);
                        label    = CreateLabel(rowIndex, item);
                        editor   = ValueEditorServices.CreateValueEdiorBase(item);
                        Grid.SetColumn(editor, 2);
                        Grid.SetRow(editor, _mainGrid.RowDefinitions.Count);

                        _editors.Add(item.Property.PropertyName, editor);
                        groupItem.Items.Add(label);
                        groupItem.Items.Add(editor);
                        groupItem.Items.Add(gridLine);
                        _mainGrid.Children.Add(label);
                        _mainGrid.Children.Add(editor);
                        _mainGrid.Children.Add(gridLine);

                        _mainGrid.RowDefinitions.Add(new RowDefinition()
                        {
                            Height = new GridLength(1d, GridUnitType.Auto)
                        });
                    }
                }

                Grid.SetRowSpan(_splitter, rowIndex + 1);
                Grid.SetRowSpan(_verticalLine, rowIndex + 1);
                _verticalLine.Stroke = groupItem.Background;
                _mainGrid.Children.Add(_splitter);
                _mainGrid.Children.Add(_verticalLine);

                _mainGrid.RowDefinitions.Add(new RowDefinition()
                {
                    Height = new GridLength(1d, GridUnitType.Star)
                });
            }
        }