Closed cdytoby closed 2 years ago
Hi,
You are setting AutoGenerateProperties to false...so no properties are displayed in the PropertyGrid. When setting this property to false, you must specify the properties you want to see with PropertyGrid.PropertyDefinitions.
The "OnPreparePropertyItem" will be called when a new property will be added to the PropertyGrid : when none are added, it won't be called.
Following your example, you could start with a PropertyGrid.AutoGenerateProperties at False and use a button click:
private void Button_Click( object sender, RoutedEventArgs e ) { editPropertyGrid.PropertyDefinitions.Add( new PropertyDefinition() { TargetProperties = new List<string>() { nameof( GameCatalogItem.name ) }, DisplayName = "test", IsBrowsable = true, Description = "des" } ); editPropertyGrid.PropertyDefinitions.Add( new PropertyDefinition() { TargetProperties = new List<string>() { nameof( GameCatalogItem.year ) } } ); }
This will add 2 properties in the PropertyGrid.
I'm going to close this one. I solved it but I don't know what I did to solve it.
Code:
CS:
XAML:
The issue:
Debug.WriteLine("EditPropertyGridOnPreparePropertyItem called");
this line is not displayed in Debug console, and the properties are not displayed in this propertygrid control, it's empty.The thing I want to achieve is, I want to add PropertyDefinitions dynamically in cs code, not in xaml, because there will be different types and I want to reuse the same property grid window. I found in documentation somewhere that I should use
PreparePropertyItem
event, but it seems it's not getting called. I can confirm that directly set propertydefinition in xaml works.Also, is it because I'm using WPF with .NET 5?