Skip to content

Commit 64cd77e

Browse files
committed
fixed #459
1 parent 940117a commit 64cd77e

File tree

4 files changed

+36
-30
lines changed

4 files changed

+36
-30
lines changed

src/Shared/HandyControl_Shared/Controls/PropertyGrid/PropertyGrid.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private void UpdateItems(object obj)
126126
{
127127
if (obj == null || _itemsControl == null) return;
128128

129-
_dataView = CollectionViewSource.GetDefaultView(TypeDescriptor.GetProperties(obj).OfType<PropertyDescriptor>()
129+
_dataView = CollectionViewSource.GetDefaultView(TypeDescriptor.GetProperties(obj.GetType()).OfType<PropertyDescriptor>()
130130
.Where(item => PropertyResolver.ResolveIsBrowsable(item)).Select(CreatePropertyItem)
131131
.Do(item => item.InitElement()));
132132

src/Shared/HandyControl_Shared/Controls/PropertyGrid/PropertyItem.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace HandyControl.Controls
88
{
9-
public class PropertyItem : Control
9+
public class PropertyItem : ListBoxItem
1010
{
1111
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register(
1212
"Value", typeof(object), typeof(PropertyItem), new PropertyMetadata(default(object)));
@@ -107,15 +107,6 @@ public FrameworkElement EditorElement
107107
set => SetValue(EditorElementProperty, value);
108108
}
109109

110-
public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register(
111-
"IsSelected", typeof(bool), typeof(PropertyItem), new PropertyMetadata(ValueBoxes.FalseBox));
112-
113-
public bool IsSelected
114-
{
115-
get => (bool)GetValue(IsSelectedProperty);
116-
set => SetValue(IsSelectedProperty, ValueBoxes.BooleanBox(value));
117-
}
118-
119110
public static readonly DependencyProperty IsExpandedEnabledProperty = DependencyProperty.Register(
120111
"IsExpandedEnabled", typeof(bool), typeof(PropertyItem), new PropertyMetadata(ValueBoxes.FalseBox));
121112

src/Shared/HandyControl_Shared/Controls/PropertyGrid/PropertyItemsControl.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,16 @@
22

33
namespace HandyControl.Controls
44
{
5-
public class PropertyItemsControl : ItemsControl
5+
public class PropertyItemsControl : ListBox
66
{
77
protected override bool IsItemItsOwnContainerOverride(object item) => item is PropertyItem;
8+
9+
public PropertyItemsControl()
10+
{
11+
#if !NET40
12+
VirtualizingPanel.SetIsVirtualizingWhenGrouping(this, true);
13+
VirtualizingPanel.SetScrollUnit(this, ScrollUnit.Pixel);
14+
#endif
15+
}
816
}
917
}

src/Shared/HandyControl_Shared/Themes/Styles/Base/PropertyGridBaseStyle.xaml

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,32 @@
8989
</Setter>
9090
</Style>
9191

92+
<Style x:Key="PropertyItemsControlBaseStyle" TargetType="hc:PropertyItemsControl">
93+
<Setter Property="ItemContainerStyle" Value="{StaticResource PropertyItemBaseStyle}"/>
94+
<Setter Property="Focusable" Value="False"/>
95+
<Setter Property="Template">
96+
<Setter.Value>
97+
<ControlTemplate TargetType="hc:PropertyItemsControl">
98+
<hc:ScrollViewer Focusable="false" HorizontalScrollBarVisibility="Disabled">
99+
<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
100+
</hc:ScrollViewer>
101+
</ControlTemplate>
102+
</Setter.Value>
103+
</Setter>
104+
<Style.Triggers>
105+
<Trigger Property="IsGrouping" Value="False">
106+
<Setter Property="ScrollViewer.CanContentScroll" Value="True"/>
107+
</Trigger>
108+
</Style.Triggers>
109+
</Style>
110+
92111
<Style x:Key="PropertyGroupItemBaseStyle" TargetType="GroupItem">
93112
<Setter Property="Margin" Value="0,0,0,6"/>
94113
<Setter Property="Padding" Value="10,6,6,0"/>
95114
<Setter Property="Template">
96115
<Setter.Value>
97116
<ControlTemplate TargetType="GroupItem">
98-
<Expander BorderThickness="1" BorderBrush="{DynamicResource BorderBrush}" Header="{Binding Name}" IsExpanded="True" Background="{DynamicResource SecondaryRegionBrush}" Foreground="{DynamicResource PrimaryTextBrush}">
117+
<Expander Name="exp" BorderThickness="1" BorderBrush="{DynamicResource BorderBrush}" Header="{Binding Name}" IsExpanded="True" Background="{DynamicResource SecondaryRegionBrush}" Foreground="{DynamicResource PrimaryTextBrush}">
99118
<Border BorderThickness="1,0,1,1" BorderBrush="{DynamicResource BorderBrush}" Background="{DynamicResource RegionBrush}" CornerRadius="0,0,4,4">
100119
<ItemsPresenter Margin="{TemplateBinding Padding}"/>
101120
</Border>
@@ -105,16 +124,6 @@
105124
</Setter>
106125
</Style>
107126

108-
<ItemsPanelTemplate x:Key="PropertyItemsControlItemsPanelTemplate">
109-
<VirtualizingStackPanel FocusVisualStyle="{x:Null}" VirtualizationMode="Recycling"/>
110-
</ItemsPanelTemplate>
111-
112-
<Style x:Key="PropertyItemsControlBaseStyle" TargetType="hc:PropertyItemsControl">
113-
<Setter Property="ItemContainerStyle" Value="{StaticResource PropertyItemBaseStyle}"/>
114-
<Setter Property="ItemsPanel" Value="{StaticResource PropertyItemsControlItemsPanelTemplate}"/>
115-
<Setter Property="Focusable" Value="False"/>
116-
</Style>
117-
118127
<Style x:Key="PropertyGridBaseStyle" TargetType="hc:PropertyGrid">
119128
<Setter Property="MaxTitleWidth" Value="200"/>
120129
<Setter Property="MinTitleWidth" Value="120"/>
@@ -142,13 +151,11 @@
142151
</hc:ButtonGroup>
143152
<hc:SearchBar x:Name="PART_SearchBar" IsRealTime="True" ShowClearButton="True" Style="{StaticResource SearchBarPlus}"/>
144153
</DockPanel>
145-
<ScrollViewer Grid.Row="1">
146-
<hc:PropertyItemsControl x:Name="PART_ItemsControl" Style="{StaticResource PropertyItemsControlBaseStyle}">
147-
<hc:PropertyItemsControl.GroupStyle>
148-
<GroupStyle ContainerStyle="{StaticResource PropertyGroupItemBaseStyle}"/>
149-
</hc:PropertyItemsControl.GroupStyle>
150-
</hc:PropertyItemsControl>
151-
</ScrollViewer>
154+
<hc:PropertyItemsControl Grid.Row="1" x:Name="PART_ItemsControl" Style="{StaticResource PropertyItemsControlBaseStyle}">
155+
<hc:PropertyItemsControl.GroupStyle>
156+
<GroupStyle ContainerStyle="{StaticResource PropertyGroupItemBaseStyle}"/>
157+
</hc:PropertyItemsControl.GroupStyle>
158+
</hc:PropertyItemsControl>
152159
</Grid>
153160
</Border>
154161
</ControlTemplate>

0 commit comments

Comments
 (0)