Propertygrid under net7 only shows a single item per category
ykarpeev opened this issue · 3 comments
After updating my project to net7 I noticed that only a single item per category is shown in category view. It will still show all of them under alphabetical mode.
Here are my results with a test project.
<xctk:PropertyGrid SelectedObject="{Binding}" />
public class MainViewModel : ObservableObject
{
public string Setting2 { get; set; }
public string Setting1 { get; set; }
}
Hello,
This is interesting.
Everything is correct in NET6 but not in NET7.
we will look into this.
Thank you for pointing this out.
Here's a fix (it will part of v4.6).
In file Xceed.Wpf.Toolkit/PropertyGrid/Implementation/PropertyItemsControl.cs, replace the constructor with:
public PropertyItemsControl()
{
this.Initialized += this.PropertyItemsControl_Initialized;
}
Then, add the 2 following methods:
private void PropertyItemsControl_Initialized( object sender, EventArgs e )
{
var propertyItemsControl = sender as PropertyItemsControl;
if( propertyItemsControl != null )
{
var propertyGrid = propertyItemsControl.TemplatedParent as PropertyGrid;
if( propertyGrid != null )
{
if( propertyGrid.IsVirtualizing )
{
this.SetVirtualizingWhenGrouping();
}
}
else
{
var propertyItem = propertyItemsControl.TemplatedParent as PropertyItem;
if( propertyItem != null )
{
propertyGrid = propertyItem.ParentElement as PropertyGrid;
if( propertyGrid != null )
{
if( propertyGrid.IsVirtualizing )
{
this.SetVirtualizingWhenGrouping();
}
}
}
}
}
}
private void SetVirtualizingWhenGrouping()
{
var propertyItemsControlProperties = TypeDescriptor.GetProperties( this, new Attribute[] { new PropertyFilterAttribute( PropertyFilterOptions.All ) } );
var prop1 = propertyItemsControlProperties.Find( "VirtualizingPanel.IsVirtualizingWhenGrouping", false );
if( prop1 != null )
{
prop1.SetValue( this, true );
}
var prop2 = propertyItemsControlProperties.Find( "VirtualizingPanel.CacheLengthUnit", false );
if( prop2 != null )
{
prop2.SetValue( this, Enum.ToObject( prop2.PropertyType, 1 ) );
}
}
Thank you.