This commit is contained in:
NaBian committed 2020-10-12 01:09:35 +08:00
1 parent 940117adc5
commit 64cd77ece0
4 files changed
+36 -30

No files matched your search

@@ -126,7 +126,7 @@ namespace HandyControl.Controls
{ {
if (obj == null || _itemsControl == null) return; if (obj == null || _itemsControl == null) return;
_dataView = CollectionViewSource.GetDefaultView(TypeDescriptor.GetProperties(obj).OfType<PropertyDescriptor>() _dataView = CollectionViewSource.GetDefaultView(TypeDescriptor.GetProperties(obj.GetType()).OfType<PropertyDescriptor>()
.Where(item => PropertyResolver.ResolveIsBrowsable(item)).Select(CreatePropertyItem) .Where(item => PropertyResolver.ResolveIsBrowsable(item)).Select(CreatePropertyItem)
.Do(item => item.InitElement())); .Do(item => item.InitElement()));
@@ -6,7 +6,7 @@ using HandyControl.Data;
namespace HandyControl.Controls namespace HandyControl.Controls
{ {
public class PropertyItem : Control public class PropertyItem : ListBoxItem
{ {
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register( public static readonly DependencyProperty ValueProperty = DependencyProperty.Register(
"Value", typeof(object), typeof(PropertyItem), new PropertyMetadata(default(object))); "Value", typeof(object), typeof(PropertyItem), new PropertyMetadata(default(object)));
@@ -107,15 +107,6 @@ namespace HandyControl.Controls
set => SetValue(EditorElementProperty, value); set => SetValue(EditorElementProperty, value);
} }
public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register(
"IsSelected", typeof(bool), typeof(PropertyItem), new PropertyMetadata(ValueBoxes.FalseBox));
public bool IsSelected
{
get => (bool)GetValue(IsSelectedProperty);
set => SetValue(IsSelectedProperty, ValueBoxes.BooleanBox(value));
}
public static readonly DependencyProperty IsExpandedEnabledProperty = DependencyProperty.Register( public static readonly DependencyProperty IsExpandedEnabledProperty = DependencyProperty.Register(
"IsExpandedEnabled", typeof(bool), typeof(PropertyItem), new PropertyMetadata(ValueBoxes.FalseBox)); "IsExpandedEnabled", typeof(bool), typeof(PropertyItem), new PropertyMetadata(ValueBoxes.FalseBox));
@@ -2,8 +2,16 @@
namespace HandyControl.Controls namespace HandyControl.Controls
{ {
public class PropertyItemsControl : ItemsControl public class PropertyItemsControl : ListBox
{ {
protected override bool IsItemItsOwnContainerOverride(object item) => item is PropertyItem; protected override bool IsItemItsOwnContainerOverride(object item) => item is PropertyItem;
public PropertyItemsControl()
{
#if !NET40
VirtualizingPanel.SetIsVirtualizingWhenGrouping(this, true);
VirtualizingPanel.SetScrollUnit(this, ScrollUnit.Pixel);
#endif
}
} }
} }
@@ -89,13 +89,32 @@
</Setter> </Setter>
</Style> </Style>
<Style x:Key="PropertyItemsControlBaseStyle" TargetType="hc:PropertyItemsControl">
<Setter Property="ItemContainerStyle" Value="{StaticResource PropertyItemBaseStyle}"/>
<Setter Property="Focusable" Value="False"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="hc:PropertyItemsControl">
<hc:ScrollViewer Focusable="false" HorizontalScrollBarVisibility="Disabled">
<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</hc:ScrollViewer>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsGrouping" Value="False">
<Setter Property="ScrollViewer.CanContentScroll" Value="True"/>
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="PropertyGroupItemBaseStyle" TargetType="GroupItem"> <Style x:Key="PropertyGroupItemBaseStyle" TargetType="GroupItem">
<Setter Property="Margin" Value="0,0,0,6"/> <Setter Property="Margin" Value="0,0,0,6"/>
<Setter Property="Padding" Value="10,6,6,0"/> <Setter Property="Padding" Value="10,6,6,0"/>
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
<ControlTemplate TargetType="GroupItem"> <ControlTemplate TargetType="GroupItem">
<Expander BorderThickness="1" BorderBrush="{DynamicResource BorderBrush}" Header="{Binding Name}" IsExpanded="True" Background="{DynamicResource SecondaryRegionBrush}" Foreground="{DynamicResource PrimaryTextBrush}"> <Expander Name="exp" BorderThickness="1" BorderBrush="{DynamicResource BorderBrush}" Header="{Binding Name}" IsExpanded="True" Background="{DynamicResource SecondaryRegionBrush}" Foreground="{DynamicResource PrimaryTextBrush}">
<Border BorderThickness="1,0,1,1" BorderBrush="{DynamicResource BorderBrush}" Background="{DynamicResource RegionBrush}" CornerRadius="0,0,4,4"> <Border BorderThickness="1,0,1,1" BorderBrush="{DynamicResource BorderBrush}" Background="{DynamicResource RegionBrush}" CornerRadius="0,0,4,4">
<ItemsPresenter Margin="{TemplateBinding Padding}"/> <ItemsPresenter Margin="{TemplateBinding Padding}"/>
</Border> </Border>
@@ -105,16 +124,6 @@
</Setter> </Setter>
</Style> </Style>
<ItemsPanelTemplate x:Key="PropertyItemsControlItemsPanelTemplate">
<VirtualizingStackPanel FocusVisualStyle="{x:Null}" VirtualizationMode="Recycling"/>
</ItemsPanelTemplate>
<Style x:Key="PropertyItemsControlBaseStyle" TargetType="hc:PropertyItemsControl">
<Setter Property="ItemContainerStyle" Value="{StaticResource PropertyItemBaseStyle}"/>
<Setter Property="ItemsPanel" Value="{StaticResource PropertyItemsControlItemsPanelTemplate}"/>
<Setter Property="Focusable" Value="False"/>
</Style>
<Style x:Key="PropertyGridBaseStyle" TargetType="hc:PropertyGrid"> <Style x:Key="PropertyGridBaseStyle" TargetType="hc:PropertyGrid">
<Setter Property="MaxTitleWidth" Value="200"/> <Setter Property="MaxTitleWidth" Value="200"/>
<Setter Property="MinTitleWidth" Value="120"/> <Setter Property="MinTitleWidth" Value="120"/>
@@ -142,13 +151,11 @@
</hc:ButtonGroup> </hc:ButtonGroup>
<hc:SearchBar x:Name="PART_SearchBar" IsRealTime="True" ShowClearButton="True" Style="{StaticResource SearchBarPlus}"/> <hc:SearchBar x:Name="PART_SearchBar" IsRealTime="True" ShowClearButton="True" Style="{StaticResource SearchBarPlus}"/>
</DockPanel> </DockPanel>
<ScrollViewer Grid.Row="1"> <hc:PropertyItemsControl Grid.Row="1" x:Name="PART_ItemsControl" Style="{StaticResource PropertyItemsControlBaseStyle}">
<hc:PropertyItemsControl x:Name="PART_ItemsControl" Style="{StaticResource PropertyItemsControlBaseStyle}"> <hc:PropertyItemsControl.GroupStyle>
<hc:PropertyItemsControl.GroupStyle> <GroupStyle ContainerStyle="{StaticResource PropertyGroupItemBaseStyle}"/>
<GroupStyle ContainerStyle="{StaticResource PropertyGroupItemBaseStyle}"/> </hc:PropertyItemsControl.GroupStyle>
</hc:PropertyItemsControl.GroupStyle> </hc:PropertyItemsControl>
</hc:PropertyItemsControl>
</ScrollViewer>
</Grid> </Grid>
</Border> </Border>
</ControlTemplate> </ControlTemplate>