You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
141 lines
4.8 KiB
141 lines
4.8 KiB
/*************************************************************************************
|
|
|
|
Toolkit for WPF
|
|
|
|
Copyright (C) 2007-2025 Xceed Software Inc.
|
|
|
|
This program is provided to you under the terms of the XCEED SOFTWARE, INC.
|
|
COMMUNITY LICENSE AGREEMENT (for non-commercial use) as published at
|
|
https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md
|
|
|
|
For more features, controls, and fast professional support,
|
|
pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/
|
|
|
|
Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids
|
|
|
|
***********************************************************************************/
|
|
|
|
using System;
|
|
using System.Windows.Controls;
|
|
using System.Windows;
|
|
using System.ComponentModel;
|
|
|
|
namespace Xceed.Wpf.Toolkit.PropertyGrid
|
|
{
|
|
public class PropertyItemsControl : ItemsControl
|
|
{
|
|
public PropertyItemsControl()
|
|
{
|
|
this.Initialized += this.PropertyItemsControl_Initialized;
|
|
}
|
|
|
|
#region PreparePropertyItemEvent Attached Routed Event
|
|
|
|
internal static readonly RoutedEvent PreparePropertyItemEvent = EventManager.RegisterRoutedEvent( "PreparePropertyItem", RoutingStrategy.Bubble, typeof( PropertyItemEventHandler ), typeof( PropertyItemsControl ) );
|
|
internal event PropertyItemEventHandler PreparePropertyItem
|
|
{
|
|
add
|
|
{
|
|
AddHandler( PropertyItemsControl.PreparePropertyItemEvent, value );
|
|
}
|
|
remove
|
|
{
|
|
RemoveHandler( PropertyItemsControl.PreparePropertyItemEvent, value );
|
|
}
|
|
}
|
|
|
|
private void RaisePreparePropertyItemEvent( PropertyItemBase propertyItem, object item )
|
|
{
|
|
this.RaiseEvent( new PropertyItemEventArgs( PropertyItemsControl.PreparePropertyItemEvent, this, propertyItem, item ) );
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region ClearPropertyItemEvent Attached Routed Event
|
|
|
|
internal static readonly RoutedEvent ClearPropertyItemEvent = EventManager.RegisterRoutedEvent( "ClearPropertyItem", RoutingStrategy.Bubble, typeof( PropertyItemEventHandler ), typeof( PropertyItemsControl ) );
|
|
internal event PropertyItemEventHandler ClearPropertyItem
|
|
{
|
|
add
|
|
{
|
|
AddHandler( PropertyItemsControl.ClearPropertyItemEvent, value );
|
|
}
|
|
remove
|
|
{
|
|
RemoveHandler( PropertyItemsControl.ClearPropertyItemEvent, value );
|
|
}
|
|
}
|
|
|
|
private void RaiseClearPropertyItemEvent( PropertyItemBase propertyItem, object item )
|
|
{
|
|
this.RaiseEvent( new PropertyItemEventArgs( PropertyItemsControl.ClearPropertyItemEvent, this, propertyItem, item ) );
|
|
}
|
|
|
|
#endregion
|
|
|
|
protected override bool IsItemItsOwnContainerOverride( object item )
|
|
{
|
|
return ( item is PropertyItemBase );
|
|
}
|
|
|
|
|
|
protected override void PrepareContainerForItemOverride( DependencyObject element, object item )
|
|
{
|
|
base.PrepareContainerForItemOverride( element, item );
|
|
this.RaisePreparePropertyItemEvent( ( PropertyItemBase )element, item );
|
|
}
|
|
|
|
protected override void ClearContainerForItemOverride( DependencyObject element, object item )
|
|
{
|
|
this.RaiseClearPropertyItemEvent( ( PropertyItemBase )element, item );
|
|
base.ClearContainerForItemOverride( element, item );
|
|
}
|
|
|
|
|
|
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 ) );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|