Мы создали собственный стиль для ListBox с расширителями в качестве раздела. Это позволило нам настроить внешний вид пунктов меню, просто стилизовав Расширитель (т. Е. Кнопки сводки, красные, если они недействительны и т. Д.). Ниже приведен фрагмент кода, который может служить отправной точкой, и вы можете настроить его в соответствии со своими требованиями. необходимо. Примечание. Привязка IsExpanded с помощью IsSelected позволяет сделать так, чтобы за раз был открыт только один расширитель, просто удалите его, если хотите, чтобы одновременно открывались мультипликаторы.
<Style x:Key="VerticalListBoxWithAutoScroll" TargetType="{x:Type ListBox}">
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Grid>
<ScrollViewer x:Name="scrollviewer">
<ScrollViewer.Template>
<ControlTemplate TargetType="{x:Type ScrollViewer}" >
<Grid >
<ScrollBar x:Name="PART_VerticalScrollBar" Orientation="Vertical"
Value="{TemplateBinding VerticalOffset}"
Maximum="{TemplateBinding ScrollableHeight}"
ViewportSize="{TemplateBinding ViewportHeight}"
Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"
Width="{Binding Width, ElementName=Panel}">
<ScrollBar.Template>
<ControlTemplate>
<Track x:Name="PART_Track">
<Track.DecreaseRepeatButton>
<RepeatButton Command="ScrollBar.PageUpCommand"
Background="White" BorderBrush="Transparent"/>
</Track.DecreaseRepeatButton>
<Track.IncreaseRepeatButton>
<RepeatButton Command="ScrollBar.PageDownCommand"
Background="White" BorderBrush="Transparent"/>
</Track.IncreaseRepeatButton>
<Track.Thumb>
<Thumb BorderBrush="Transparent"
Background="White" Opacity="0.8" />
</Track.Thumb>
</Track>
</ControlTemplate>
</ScrollBar.Template>
</ScrollBar>
<ScrollContentPresenter Height="Auto" VerticalAlignment="Center"/>
</Grid>
</ControlTemplate>
</ScrollViewer.Template>
<ItemsPresenter/>
</ScrollViewer>
<Grid x:Name="Panel">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<RepeatButton Grid.Row="0" x:Name="LineUpButton" Height="30" Width="80" HorizontalAlignment="Center" Opacity="0" Visibility="Collapsed"
Style="{StaticResource ScrollBarLineButton}"
Content="M 0 8 L 8 8 L 4 0 Z"
Command="{x:Static ScrollBar.LineUpCommand}"
CommandTarget="{Binding ElementName=scrollviewer}"
ClickMode="Hover" />
<RepeatButton Grid.Row="2" x:Name="LineDownButton" Height="30" Width="80" HorizontalAlignment="Center" Opacity="0" Visibility="Collapsed"
Style="{StaticResource ScrollBarLineButton}"
Content="M 0 0 L 4 8 L 8 0 Z"
Command="{x:Static ScrollBar.LineDownCommand}"
CommandTarget="{Binding ElementName=scrollviewer}"
ClickMode="Hover"/>
</Grid>
</Grid>
<ControlTemplate.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True"/>
<Condition Property="ComputedVerticalScrollBarVisibility" SourceName="scrollviewer" Value="Visible"/>
</MultiTrigger.Conditions>
<MultiTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="LineUpButton"
Storyboard.TargetProperty="Opacity" To="0.8" Duration="0:0:0.25"/>
<DoubleAnimation Storyboard.TargetName="LineDownButton"
Storyboard.TargetProperty="Opacity" To="0.8" Duration="0:0:0.25"/>
</Storyboard>
</BeginStoryboard>
</MultiTrigger.EnterActions>
<MultiTrigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="LineUpButton"
Storyboard.TargetProperty="Opacity" To="0" Duration="0:0:0.25"/>
<DoubleAnimation Storyboard.TargetName="LineDownButton"
Storyboard.TargetProperty="Opacity" To="0" Duration="0:0:0.25"/>
</Storyboard>
</BeginStoryboard>
</MultiTrigger.ExitActions>
<Setter TargetName="LineUpButton" Property="Visibility" Value="Visible" />
<Setter TargetName="LineDownButton" Property="Visibility" Value="Visible" />
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="ItemTemplate">
<Setter.Value >
<DataTemplate>
<StackPanel Background="White">
<Expander Content="{Binding}" Width="Auto" Header="{Binding DisplayName}"
IsExpanded="{Binding IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBoxItem}}}" >
</Expander>
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>