This is a migrated thread and some comments may be shown as answers.

Dynamic Property Grid Issue

3 Answers 307 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Ryan
Top achievements
Rank 1
Ryan asked on 22 Sep 2011, 05:49 PM
Let me start by saying that I am fairly new to WPF development so it's likely the problem is just something I'm doing wrong. In my application I have several elements which can be selected and we would like to have their (custom) properties displayed in a RadPropertyGrid in a docked pane. The way I have set it up is that each element has a PropertyPane user control which contains a RadPropertyGrid, and when the element is clicked the element's PropertyPane should be set as the content of the RadPane in the MainWindow. From what I can tell the PropertyPane seems to have a valid RadPropertyGrid when it is being set as the content, but when the content is displayed the RadPropertyGrid is empty.

The section in the MainWindow where the PropertyPane is inserted:
<!-- Properties Pane -->
<telerik:RadSplitContainer InitialPosition="DockedRight">
     <telerik:RadPaneGroup>
          <telerik:RadPane Name="propertyPane" Header="Properties" CanUserClose="False">
          </telerik:RadPane>
     </telerik:RadPaneGroup>
</telerik:RadSplitContainer>


The user control which contains the RadPropertyGrid:
<UserControl x:Class="App.PropertiesPane"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
             mc:Ignorable="d"
             d:DesignHeight="300" d:DesignWidth="300">
  
    <Grid>
        <telerik:RadPropertyGrid AutoGeneratePropertyDefinitions="False" Name="PropertyGrid" />      
    </Grid>
</UserControl>

And the code for the element class which should update the RadPropertyGrid:
public class DiagramControlTextBox : TextBox{
     public PropertiesPane PropPane;
     public Telerik.Windows.Controls.RadPropertyGrid DCProperties;
     public int Size;
     public int Weight;
   
     public void updatePropertiesPane(object sender, RoutedEventArgs e)
     {
          App.Current.MainWindow.propertyPane.Content = this.PropPane;
     }
    
     public void initializePropertiesPane()
     {
          this.PropPane = new PropertiesPane();
          this.DCProperties = new Telerik.Windows.Controls.RadPropertyGrid();
   
          Telerik.Windows.Controls.Data.PropertyGrid.PropertyDefinition sizeProperty = new Telerik.Windows.Controls.Data.PropertyGrid.PropertyDefinition()
          {
               DisplayName = "Size",
               Binding = new Binding { Source = this.Size }
          };
   
          Telerik.Windows.Controls.Data.PropertyGrid.PropertyDefinition weightProperty = new Telerik.Windows.Controls.Data.PropertyGrid.PropertyDefinition()
          {
               DisplayName = "Weight",
               Binding = new Binding { Source = this.Weight }
          };
   
          this.DCProperties.AutoGeneratePropertyDefinitions = false;
   
          this.DCProperties.SearchBoxVisibility = System.Windows.Visibility.Hidden;
          this.DCProperties.DescriptionPanelVisibility = System.Windows.Visibility.Hidden;
   
          this.DCProperties.PropertyDefinitions.Add(sizeProperty);
          this.DCProperties.PropertyDefinitions.Add(weightProperty);
   
          this.DCProperties.Item = this;
          this.PropPane.PropertyGrid = this.DCProperties;
     }     
}

3 Answers, 1 is accepted

Sort by
0
Ivan Ivanov
Telerik team
answered on 27 Sep 2011, 04:30 PM
Hello Ryan,

Reinitializing the RadPropertyGrid instance like this:
this.PropPane.PropertyGrid = this.DCProperties;
is not a good practice and in your scenario the UI never gets notified of this change. Another issue with this code is that your PropertyDefinitions are bound to fields. You should introduce properties that expose these fields' values and bind the PropertyDefinitions to them. I would advise you to design an architecture that separates the data from the used visual objects. This will prevent you from many issue in the puture.

Kind regards,
Ivan Ivanov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
Hyunho
Top achievements
Rank 1
answered on 29 Mar 2013, 02:32 PM
Hello,
I want to know how to implement a dynamic property grid with MVVM.
If I have two object elements, One is a house and another is a person, and properties of Them is different each other.
When I select the item, property grid should display properties of the item.
Could you give me a simple example for this?
0
Ivan Ivanov
Telerik team
answered on 29 Mar 2013, 03:31 PM
Hello Hyunho,

 RadPropertyGrid automatically reevaluates its PropertyDefinitions, as soon as its Item gets changed, regardless of the Item type. Please refer to our demos for some working examples.

Kind regards,
Ivan Ivanov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
PropertyGrid
Asked by
Ryan
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
Hyunho
Top achievements
Rank 1
Share this question
or