Files
ShrlAlgoToolkit/NeuWPF/NeoUI/Controls/ListBoxStyle.xaml
ShrlAlgo 955a01f564 整理
2025-08-20 12:10:35 +08:00

294 lines
18 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:assists="clr-namespace:NeoUI.Assists"
xmlns:conv="clr-namespace:NeoUI.Converters"
xmlns:internal="clr-namespace:NeoUI.Converters.Internal"
xmlns:nvd="clr-namespace:NeoUI.Controls.Decorations"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<!-- 不支持垂直方向 -->
<Style TargetType="ListBox" x:Key="SlideTabGroupListBoxStyle">
<Setter Property="Background" Value="{DynamicResource ControlBackgroundNormalBrush}" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="assists:ControlAssist.CornerRadius" Value="4" />
<Setter Property="assists:SelectorAssist.Orientation" Value="Horizontal" />
<Setter Property="Foreground" Value="{DynamicResource TextPrimaryBrush}" />
<Setter Property="ItemContainerStyle">
<Setter.Value>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Background" Value="Transparent" />
<Setter Property="Foreground" Value="{DynamicResource TextSecondaryBrush}" />
<!-- 默认文字颜色 -->
<Setter Property="FontSize" Value="16" />
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<Setter Property="Padding" Value="15,10" />
<!-- 增加一些内边距让选项卡不那么拥挤 -->
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Grid Background="Transparent">
<ContentPresenter
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Margin="{TemplateBinding Padding}"
TextElement.Foreground="{TemplateBinding Foreground}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<!-- 被选中时,仅改变文字颜色 -->
<Setter Property="Foreground" Value="{DynamicResource PrimaryNormalBrush}" />
<!-- 主题高亮颜色 -->
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Setter.Value>
</Setter>
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<StackPanel Orientation="{Binding Path=(assists:SelectorAssist.Orientation), RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBox}}" />
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBox">
<Grid>
<nvd:EmbossBorder
CornerRadius="{TemplateBinding assists:ControlAssist.CornerRadius}"
Intensity="0.8"
Margin="-4" />
<!-- Canvas 用于精确定位滑块 -->
<Canvas>
<!-- 滑块元素Name 是关键,行为代码通过它来查找并控制动画 -->
<nvd:SlotBorder
CornerRadius="{Binding Path=(assists:ControlAssist.CornerRadius), RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBox}}"
Intensity="0.2"
Padding="-4"
ShaderEnabled="True"
x:Name="PART_SelectionIndicator">
<nvd:SlotBorder.RenderTransform>
<TranslateTransform />
</nvd:SlotBorder.RenderTransform>
</nvd:SlotBorder>
</Canvas>
<!-- ItemsPresenter 必须在滑块上层,以显示所有 Tab 项 -->
<ItemsPresenter />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="ListBox" x:Key="TabGroupListBoxStyle">
<Setter Property="Background" Value="{DynamicResource ControlBackgroundNormalBrush}" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="assists:SelectorAssist.Orientation" Value="Horizontal" />
<Setter Property="assists:ControlAssist.CornerRadius" Value="10" />
<!-- 关键将上面定义的Item样式应用到ListBox的每个项目上 -->
<Setter Property="ItemContainerStyle">
<Setter.Value>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Background" Value="Transparent" />
<Setter Property="Foreground" Value="{DynamicResource TextPrimaryBrush}" />
<Setter Property="FontSize" Value="16" />
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Grid>
<nvd:EmbossBorder
Background="{TemplateBinding Background}"
CornerRadius="{Binding Path=(assists:ControlAssist.CornerRadius), RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBox}}"
Cursor="Hand"
ShaderEnabled="False"
x:Name="emboss">
<ContentPresenter
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Margin="10"
TextElement.Foreground="{TemplateBinding Foreground}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
</nvd:EmbossBorder>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="ShaderEnabled" TargetName="emboss" Value="True" />
<Setter Property="Background" TargetName="emboss" Value="{DynamicResource BackgroundFloatingBrush}" />
<Setter Property="Foreground" Value="{DynamicResource PrimaryNormalBrush}" />
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Foreground" Value="{DynamicResource PrimaryNormalBrush}" />
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Duration="0:0:0.3"
Storyboard.TargetName="emboss"
Storyboard.TargetProperty="Intensity"
To="1" />
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Duration="0:0:0.3"
Storyboard.TargetName="emboss"
Storyboard.TargetProperty="Intensity"
To="0" />
</Storyboard>
</BeginStoryboard>
</Trigger.ExitActions>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Setter.Value>
</Setter>
<!-- 设置布局面板为水平排列 -->
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<StackPanel Orientation="{Binding Path=(assists:SelectorAssist.Orientation), RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBox}}" />
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBox">
<nvd:SlotBorder
CornerRadius="{TemplateBinding assists:ControlAssist.CornerRadius}"
Intensity="0.8"
Padding="-4">
<ItemsPresenter />
</nvd:SlotBorder>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type ListBoxItem}" x:Key="ListBoxItemContainerDefault">
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="Padding" Value="10,4" />
<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="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="FocusVisualStyle" Value="{DynamicResource FocusVisual}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Grid>
<Border
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="4"
Padding="{TemplateBinding Padding}"
SnapsToDevicePixels="true"
x:Name="Bd">
<ContentPresenter
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
</Border>
<!-- 偶数行颜色 -->
<Border
Background="{DynamicResource BackgroundInterlacedBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="4"
IsHitTestVisible="False"
Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(ItemsControl.AlternationIndex), Converter={x:Static internal:InterlacedBackgroundConverter.Instance}}" />
</Grid>
<ControlTemplate.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True" />
</MultiTrigger.Conditions>
<Setter Property="Background" TargetName="Bd" Value="{DynamicResource ControlBackgroundHoverBrush}" />
</MultiTrigger>
<!-- 选中对象无焦点 -->
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="Selector.IsSelectionActive" Value="False" />
<Condition Property="IsSelected" Value="True" />
</MultiTrigger.Conditions>
<Setter Property="Background" TargetName="Bd" Value="{DynamicResource ControlBackgroundSelectedBrush}" />
</MultiTrigger>
<!-- 选中对象有焦点 -->
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="Selector.IsSelectionActive" Value="True" />
<Condition Property="IsSelected" Value="True" />
</MultiTrigger.Conditions>
<Setter Property="Background" TargetName="Bd" Value="{DynamicResource PrimaryNormalBrush}" />
<Setter Property="TextElement.Foreground" TargetName="Bd" Value="{DynamicResource TextOnAccentPrimaryBrush}" />
</MultiTrigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="TextElement.Foreground" TargetName="Bd" Value="{DynamicResource TextDisabledBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style BasedOn="{StaticResource ListBoxItemContainerDefault}" TargetType="{x:Type ListBoxItem}" />
<Style TargetType="{x:Type ListBox}" x:Key="ListBoxDefault">
<Setter Property="Background" Value="{DynamicResource BackgroundFloatingBrush}" />
<Setter Property="BorderBrush" Value="{DynamicResource BorderNormalBrush}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Foreground" Value="{DynamicResource TextPrimaryBrush}" />
<Setter Property="FontSize" Value="14" />
<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="ItemContainerStyle" Value="{StaticResource ListBoxItemContainerDefault}" />
<Setter Property="AlternationCount" Value="{Binding RelativeSource={RelativeSource Self}, Path=Items.Count}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBox}">
<Border
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="4"
Padding="2"
SnapsToDevicePixels="true"
x:Name="Bd">
<ScrollViewer Focusable="false" Padding="{TemplateBinding Padding}">
<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</ScrollViewer>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Background" TargetName="Bd" Value="{DynamicResource ControlBackgroundDisabledBrush}" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsGrouping" Value="true" />
<Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping" Value="false" />
</MultiTrigger.Conditions>
<Setter Property="ScrollViewer.CanContentScroll" Value="false" />
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style BasedOn="{StaticResource ListBoxDefault}" TargetType="{x:Type ListBox}" />
</ResourceDictionary>