목표가 너무 쉽지는 않지만 도달하는 것이 불가능하지는 않습니다. 당신이 볼 수 있듯이
<local:ItemsVisibleConverter x:Key="ItemsVisibleConverter" />
<Style x:Key="CustomPropertyItemGroupContainerStyle" TargetType="{x:Type GroupItem}">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Border>
<Expander Style="{StaticResource ExpanderStyle}" Header="{Binding Name}" IsExpanded="True">
<ItemsPresenter />
</Expander>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Items, Converter={StaticResource ItemsVisibleConverter}}" Value="False">
<Setter Property="Visibility" Value="Collapsed" />
</DataTrigger>
</Style.Triggers>
</Style>
, 그것은 간단한 계산기 사용 : 우리는 눈에 보이는 특성이없는 카테고리 숨겨진 만들기위한 우리의 스타일을 만드는 데 필요한 모든 먼저
public class ItemsVisibleConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
IEnumerable itemCollection = value as IEnumerable;
if (itemCollection != null)
{
foreach (PropertyItem propertyItem in itemCollection)
{
if (propertyItem.Visibility == Visibility.Visible)
{
return true;
}
}
}
return false;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
및 다른 자원 (I) ILSpy를 사용하여 표준들에서 그들을 복사 :
<SolidColorBrush x:Key="GlyphBrush" Color="#FF31347C" />
<ControlTemplate x:Key="ExpanderToggleButton" TargetType="{x:Type ToggleButton}">
<Grid>
<Rectangle Name="Rectangle" Margin="0,0,0,0" Fill="#00FFFFFF" />
<Path Name="Up_Arrow" HorizontalAlignment="Center" VerticalAlignment="Center" Fill="{StaticResource GlyphBrush}" Data="M0,0L4,4 8,0z" RenderTransformOrigin="0.5,0.5">
<Path.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="1" ScaleY="1" />
<SkewTransform AngleX="0" AngleY="0" />
<RotateTransform Angle="-90" />
<TranslateTransform X="0" Y="0" />
</TransformGroup>
</Path.RenderTransform>
</Path>
<Path Name="Down_Arrow" Visibility="Collapsed" HorizontalAlignment="Center" VerticalAlignment="Center" Fill="{StaticResource GlyphBrush}" Data="M0,4L4,0 8,4z" RenderTransformOrigin="0.5,0.5">
<Path.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="1" ScaleY="1" />
<SkewTransform AngleX="0" AngleY="0" />
<RotateTransform Angle="135" />
<TranslateTransform X="0" Y="0" />
</TransformGroup>
</Path.RenderTransform>
</Path>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="ToggleButton.IsChecked" Value="true">
<Setter TargetName="Down_Arrow" Property="UIElement.Visibility" Value="Visible" />
<Setter TargetName="Up_Arrow" Property="UIElement.Visibility" Value="Collapsed" />
<Setter TargetName="Down_Arrow" Property="UIElement.OpacityMask" Value="#FF000000" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<Style x:Key="ExpanderStyle" TargetType="{x:Type Expander}">
<Setter Property="Control.Padding" Value="0" />
<Setter Property="Control.Background" Value="#FFF0F0F0" />
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Expander}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Name="ContentRow" Height="*" />
</Grid.RowDefinitions>
<Border Name="Border" Background="{TemplateBinding Control.Background}" BorderBrush="#FFF0F0F0">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ToggleButton Template="{StaticResource ExpanderToggleButton}" OverridesDefaultStyle="True" IsChecked="{Binding Path=IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" />
<ContentPresenter Grid.Column="1" Margin="1" RecognizesAccessKey="True" ContentSource="Header" TextElement.FontWeight="Bold" />
</Grid>
</Border>
<Border Name="ExpandSite" Visibility="Collapsed" Grid.Row="1" Background="{x:Static SystemColors.ControlBrush}" Padding="10 0 0 0">
<Border BorderThickness="0" Margin="0" Padding="0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<ContentPresenter HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}" Margin="{TemplateBinding Control.Padding}" VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}" Focusable="False" />
</Border>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="Expander.IsExpanded" Value="True">
<Setter TargetName="ExpandSite" Property="UIElement.Visibility" Value="Visible" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
이제 우리는 t에 우리의 스타일을 설정하기위한 PropertyGrid
제어를 확장 할 필요가 그는 PropertyGrid
에 포함 PropertyItemsControl
:
public class PropertyGrid : Xceed.Wpf.Toolkit.PropertyGrid.PropertyGrid
{
public GroupStyle GroupStyle
{
get;
set;
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
PropertyItemsControl propertyItemsControl =
Template.FindName("PART_PropertyItemsControl", this) as PropertyItemsControl;
propertyItemsControl.GroupStyle.Clear();
propertyItemsControl.GroupStyle.Add(GroupStyle);
}
}
그래서 당신의 XAML은 내가 당신을 도울 수 있기를 바랍니다
<local:PropertyGrid x:Name="pg">
<local:PropertyGrid.GroupStyle>
<GroupStyle ContainerStyle="{StaticResource CustomPropertyItemGroupContainerStyle}" />
</local:PropertyGrid.GroupStyle>
</local:PropertyGrid>
될 것입니다.
위대한 답변 감사합니다. 그것은 작동하지만, 첫 번째 레이어에 대해서만, 만약 내가 ExpandleObjects 하위 카테고리를 사용하지 않는 valueConverter,하지만 난 이유가 없어. – Suplanus
당신은 당신의 상황에 대해 자세한 정보를 제공해야한다, 또는 어쩌면 당신은 @Suplanus 다른 질문을 게시해야합니다 상황이 –
문제 상황이 분명하지 않다 : - 카테고리 1 - Category1.1 - 구분 2 - Category2.1 을 - 항목 따라서 Category1 및 Category1.1을 축소해야합니다. – Suplanus