Skip to content

Commit

Permalink
fixed #459
Browse files Browse the repository at this point in the history
  • Loading branch information
NaBian committed Oct 11, 2020
1 parent 940117a commit 64cd77e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private void UpdateItems(object obj)
{
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)
.Do(item => item.InitElement()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace HandyControl.Controls
{
public class PropertyItem : Control
public class PropertyItem : ListBoxItem
{
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register(
"Value", typeof(object), typeof(PropertyItem), new PropertyMetadata(default(object)));
Expand Down Expand Up @@ -107,15 +107,6 @@ public FrameworkElement EditorElement
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(
"IsExpandedEnabled", typeof(bool), typeof(PropertyItem), new PropertyMetadata(ValueBoxes.FalseBox));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@

namespace HandyControl.Controls
{
public class PropertyItemsControl : ItemsControl
public class PropertyItemsControl : ListBox
{
protected override bool IsItemItsOwnContainerOverride(object item) => item is PropertyItem;

public PropertyItemsControl()
{
#if !NET40
VirtualizingPanel.SetIsVirtualizingWhenGrouping(this, true);
VirtualizingPanel.SetScrollUnit(this, ScrollUnit.Pixel);
#endif
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,32 @@
</Setter>
</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">
<Setter Property="Margin" Value="0,0,0,6"/>
<Setter Property="Padding" Value="10,6,6,0"/>
<Setter Property="Template">
<Setter.Value>
<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">
<ItemsPresenter Margin="{TemplateBinding Padding}"/>
</Border>
Expand All @@ -105,16 +124,6 @@
</Setter>
</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">
<Setter Property="MaxTitleWidth" Value="200"/>
<Setter Property="MinTitleWidth" Value="120"/>
Expand Down Expand Up @@ -142,13 +151,11 @@
</hc:ButtonGroup>
<hc:SearchBar x:Name="PART_SearchBar" IsRealTime="True" ShowClearButton="True" Style="{StaticResource SearchBarPlus}"/>
</DockPanel>
<ScrollViewer Grid.Row="1">
<hc:PropertyItemsControl x:Name="PART_ItemsControl" Style="{StaticResource PropertyItemsControlBaseStyle}">
<hc:PropertyItemsControl.GroupStyle>
<GroupStyle ContainerStyle="{StaticResource PropertyGroupItemBaseStyle}"/>
</hc:PropertyItemsControl.GroupStyle>
</hc:PropertyItemsControl>
</ScrollViewer>
<hc:PropertyItemsControl Grid.Row="1" x:Name="PART_ItemsControl" Style="{StaticResource PropertyItemsControlBaseStyle}">
<hc:PropertyItemsControl.GroupStyle>
<GroupStyle ContainerStyle="{StaticResource PropertyGroupItemBaseStyle}"/>
</hc:PropertyItemsControl.GroupStyle>
</hc:PropertyItemsControl>
</Grid>
</Border>
</ControlTemplate>
Expand Down

0 comments on commit 64cd77e

Please sign in to comment.