Files
ShrlAlgoToolkit/WPFDark/StandardControls/TreeView.xaml
ShrlAlgo 4d35cadb56 更新
2025-07-11 09:20:23 +08:00

193 lines
11 KiB
XML

<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:controls="clr-namespace:WPFDark.Controls"
xmlns:internals="clr-namespace:WPFDark.Internals"
xmlns:wpf="clr-namespace:WPFDark"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="{x:Type TreeView}">
<Setter Property="Background" Value="{DynamicResource TextBoxBackgroundBrushKey}" />
<Setter Property="BorderBrush" Value="{DynamicResource TextBoxBorderBrushKey}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Foreground" Value="{DynamicResource TextBoxForegroundBrushKey}" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" />
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
<Setter Property="ScrollViewer.CanContentScroll" Value="True" />
<Setter Property="ScrollViewer.PanningMode" Value="Both" />
<Setter Property="Stylus.IsFlicksEnabled" Value="False" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="VirtualizingPanel.IsVirtualizing" Value="True" />
<Setter Property="VirtualizingPanel.VirtualizationMode" Value="Recycling" />
<Setter Property="VirtualizingStackPanel.ScrollUnit" Value="Pixel" />
<Setter Property="VirtualizingStackPanel.CacheLength" Value="20,20" />
<Setter Property="VirtualizingStackPanel.CacheLengthUnit" Value="Item" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TreeView">
<controls:BiaClippingBorder
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{x:Static wpf:Boxes.GroupCornerRadius}"
x:Name="Bd">
<ScrollViewer Focusable="False">
<ItemsPresenter />
</ScrollViewer>
</controls:BiaClippingBorder>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" Value="{DynamicResource InactiveBackgroundBrushKey}" />
<Setter Property="BorderBrush" Value="{DynamicResource InactiveBorderBrushKey}" />
<Setter Property="Foreground" Value="{DynamicResource InactiveForegroundBrushKey}" />
</Trigger>
</Style.Triggers>
</Style>
<!-- https://stackoverflow.com/questions/664632/highlight-whole-treeviewitem-line-in-wpf -->
<Style TargetType="ToggleButton" x:Key="ExpandCollapseToggleStyle">
<Setter Property="Focusable" Value="False" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToggleButton">
<Canvas
Background="Transparent"
Height="15"
Width="15">
<Path Data="M 5.367188 10.363281 L 8.230469 7.5 L 5.367188 4.632812 L 6.25 3.75 L 10 7.5 L 6.25 11.25 Z M 5.367188 10.363281" x:Name="ExpandPath">
<Path.Style>
<Style TargetType="{x:Type Path}">
<Setter Property="Fill" Value="{DynamicResource ForegroundBrushKey}" />
<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Fill" Value="{DynamicResource InactiveForegroundBrushKey}" />
</Trigger>
</Style.Triggers>
</Style>
</Path.Style>
</Path>
</Canvas>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Data" TargetName="ExpandPath" Value="M 4.632812 5.363281 L 7.5 8.230469 L 10.367188 5.363281 L 11.25 6.25 L 7.5 10 L 3.75 6.25 Z M 4.632812 5.363281" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="TreeViewItemFocusVisualStyle">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Border>
<Rectangle
Margin="0"
Opacity="0.0"
Stroke="White"
StrokeDashArray="1 2"
StrokeThickness="5.0" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type TreeViewItem}" x:Key="{x:Type TreeViewItem}">
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="Padding" Value="1" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
<Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
<Setter Property="FocusVisualStyle" Value="{StaticResource TreeViewItemFocusVisualStyle}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TreeViewItem}">
<StackPanel>
<Border
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Name="Bd"
Padding="{TemplateBinding Padding}">
<Grid>
<Grid.Style>
<Style TargetType="{x:Type Grid}">
<Setter Property="Margin">
<Setter.Value>
<MultiBinding Converter="{x:Static wpf:Constants.LengthConverter}">
<Binding RelativeSource="{RelativeSource TemplatedParent}" />
</MultiBinding>
</Setter.Value>
</Setter>
</Style>
</Grid.Style>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="19" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<!-- x:NameはWPFDark.Internals.Constants.TreeViewItemExpanderName -->
<ToggleButton
ClickMode="Press"
IsChecked="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}}"
Style="{StaticResource ExpandCollapseToggleStyle}"
x:Name="Expander" />
<ContentPresenter
ContentSource="Header"
Grid.Column="1"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
x:Name="PART_Header" />
</Grid>
</Border>
<ItemsPresenter x:Name="ItemsHost" />
</StackPanel>
<ControlTemplate.Triggers>
<Trigger Property="internals:TreeViewHelper.IsMouseDirectlyOverItem" Value="True">
<Setter Property="Background" TargetName="Bd" Value="{DynamicResource ActiveBackgroundBrushKey}" />
<Setter Property="BorderBrush" TargetName="Bd" Value="{DynamicResource ActiveBackgroundBrushKey}" />
</Trigger>
<Trigger Property="IsExpanded" Value="False">
<Setter Property="Visibility" TargetName="ItemsHost" Value="Collapsed" />
</Trigger>
<Trigger Property="HasItems" Value="False">
<Setter Property="Visibility" TargetName="Expander" Value="Hidden" />
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" TargetName="Bd" Value="{DynamicResource Item.SelectedInactive.Background}" />
<Setter Property="BorderBrush" TargetName="Bd" Value="{DynamicResource Item.SelectedInactive.Border}" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="True" />
<Condition Property="IsMouseOver" Value="True" />
</MultiTrigger.Conditions>
<Setter Property="Background" TargetName="Bd" Value="{DynamicResource Item.SelectedActive.Background.IsMouseOver}" />
<Setter Property="BorderBrush" TargetName="Bd" Value="{DynamicResource Item.SelectedActive.Border.IsMouseOver}" />
</MultiTrigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>