xceedsoftware / wpftoolkit

All the controls missing in WPF. Over 1 million downloads.
Other
3.91k stars 879 forks source link

PropertyGrid with PropertyDefinitions remains empty #1483

Open gnimor opened 5 years ago

gnimor commented 5 years ago

I tried to assign custom property definitions as mentioned on the documentation page. When I add the XAML code as shown below, the property grid remains empty. I tried the same within code and also the grid stays empty.

With Code:

            var propInfo = new PropertyDefinition();
            propInfo.DisplayName = "Just a test";
            propInfo.IsBrowsable = true;
            _propertyGrid.PropertyDefinitions.Add(propInfo);

Is this a bug or did I miss something here?

With XAML

<xctk:PropertyGrid x:Name="_propertyGrid" Width="450" Margin="10"
                                     AutoGenerateProperties="False">
                <!-- Only the following properties will be displayed in the PropertyGrid -->
                <xctk:PropertyGrid.PropertyDefinitions>
                    <xctk:PropertyDefinition TargetProperties="FirstName" />
                    <xctk:PropertyDefinition TargetProperties="FavoriteColor" />
                    <xctk:PropertyDefinition TargetProperties="PetNames" />
                </xctk:PropertyGrid.PropertyDefinitions>
            </xctk:PropertyGrid>
XceedBoucherS commented 5 years ago

Hi, You didn't specified the PropertyGrid's Selected Object. Here's a sample: ` <xctk:PropertyGrid x:Name="_propertyGrid" Width="450" Margin="10" SelectedObject="{Binding MyData}" AutoGenerateProperties="False">

  <xctk:PropertyGrid.PropertyDefinitions>
    <xctk:PropertyDefinition TargetProperties="FirstName" />
  </xctk:PropertyGrid.PropertyDefinitions>
</xctk:PropertyGrid>`

` public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); this.DataContext = this; this.MyData = new MyData() { FirstName = "Tom", LastName = "Sawyer" }; }

public MyData MyData
{
  get;
  set;
}

}

public class MyData { public string FirstName { get; set; }

public string LastName
{
  get;
  set;
}

}`


Get more controls, features, updates and technical support with Xceed Toolkit Plus for WPF