Files
Shrlalgo.RvKits/WPFluent/Controls/NumberBox/NumberBox.xaml
ShrlAlgo 4d35cadb56 更新
2025-07-11 09:20:23 +08:00

252 lines
18 KiB
XML

<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:controls="clr-namespace:WPFluent.Controls"
xmlns:system="clr-namespace:System;assembly=mscorlib"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/WPFluent;component/Resources/Variables.xaml" />
</ResourceDictionary.MergedDictionaries>
<Thickness x:Key="NumberBoxBorderThemeThickness">1,1,1,1</Thickness>
<Thickness x:Key="NumberBoxAccentBorderThemeThickness">0,0,0,1</Thickness>
<Thickness x:Key="NumberBoxLeftIconMargin">10,8,0,0</Thickness>
<Thickness x:Key="NumberBoxRightIconMargin">0,8,10,0</Thickness>
<Thickness x:Key="NumberBoxButtonMargin">0,5,4,0</Thickness>
<Thickness x:Key="NumberBoxButtonPadding">0,0,0,0</Thickness>
<system:Double x:Key="NumberBoxButtonHeight">24</system:Double>
<system:Double x:Key="NumberBoxButtonIconSize">14</system:Double>
<Style TargetType="{x:Type controls:NumberBox}" x:Key="DefaultUiNumberBoxStyle">
<!-- Universal WPF UI focus -->
<Setter Property="FocusVisualStyle" Value="{DynamicResource DefaultControlFocusVisualStyle}" />
<!-- Universal WPF UI focus -->
<!-- Universal WPF UI ContextMenu -->
<Setter Property="ContextMenu" Value="{DynamicResource DefaultControlContextMenu}" />
<!-- Universal WPF UI ContextMenu -->
<Setter Property="Foreground" Value="{DynamicResource TextFillColorPrimaryBrush}" />
<Setter Property="CaretBrush" Value="{DynamicResource TextFillColorPrimaryBrush}" />
<Setter Property="Cursor" Value="Arrow" />
<Setter Property="Background" Value="{DynamicResource ControlFillColorDefaultBrush}" />
<Setter Property="BorderBrush" Value="{DynamicResource TextControlElevationBorderBrush}" />
<Setter Property="BorderThickness" Value="{StaticResource NumberBoxBorderThemeThickness}" />
<Setter Property="FontSize" Value="{StaticResource ControlContentThemeFontSize}" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Top" />
<Setter Property="MinHeight" Value="{StaticResource TextControlThemeMinHeight}" />
<Setter Property="MinWidth" Value="{StaticResource TextControlThemeMinWidth}" />
<Setter Property="Padding" Value="{StaticResource TextControlThemePadding}" />
<Setter Property="Border.CornerRadius" Value="{StaticResource ControlCornerRadius}" />
<Setter Property="ClearButtonEnabled" Value="True" />
<Setter Property="IconPlacement" Value="Left" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type controls:NumberBox}">
<Grid HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}">
<Border
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding Border.CornerRadius}"
Height="{TemplateBinding Height}"
HorizontalAlignment="Stretch"
MinHeight="{TemplateBinding MinHeight}"
MinWidth="{TemplateBinding MinWidth}"
Padding="0"
VerticalAlignment="Stretch"
Width="{TemplateBinding Width}"
x:Name="ContentBorder">
<Grid HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid Background="Transparent" Grid.Column="0">
<ContentControl
Content="{TemplateBinding Icon}"
FontSize="16"
Foreground="{TemplateBinding Foreground}"
IsTabStop="False"
Margin="{StaticResource NumberBoxLeftIconMargin}"
Padding="0"
VerticalAlignment="Top"
x:Name="ControlIconLeft" />
</Grid>
<Grid
Background="Transparent"
Grid.Column="1"
x:Name="TextContentArea">
<Grid Margin="{TemplateBinding Padding}">
<controls:PassiveScrollViewer
Style="{DynamicResource DefaultTextBoxScrollViewerStyle}"
TextElement.Foreground="{TemplateBinding Foreground}"
x:Name="PART_ContentHost" />
<TextBlock
Foreground="{DynamicResource TextFillColorSecondaryBrush}"
Margin="0"
Padding="1,0"
Text="{TemplateBinding PlaceholderText}"
VerticalAlignment="Top"
x:Name="PlaceholderTextBox" />
</Grid>
</Grid>
<!-- Buttons and Icons have no padding from the main element to allow absolute positions if height is larger than the text entry zone -->
<StackPanel
Background="Transparent"
Grid.Column="2"
Orientation="Horizontal">
<Button
Background="Transparent"
BorderBrush="Transparent"
Focusable="False"
Foreground="{DynamicResource TextFillColorSecondaryBrush}"
Height="{StaticResource NumberBoxButtonHeight}"
HorizontalAlignment="Center"
HorizontalContentAlignment="Center"
IsTabStop="False"
Margin="{StaticResource NumberBoxButtonMargin}"
Padding="{StaticResource NumberBoxButtonPadding}"
VerticalAlignment="Top"
VerticalContentAlignment="Center"
Width="{StaticResource NumberBoxButtonHeight}"
x:Name="PART_ClearButton">
<controls:SymbolIcon FontSize="{StaticResource NumberBoxButtonIconSize}" Symbol="Dismiss24" />
</Button>
<RepeatButton
Background="Transparent"
BorderBrush="Transparent"
Foreground="{DynamicResource TextFillColorSecondaryBrush}"
Height="{StaticResource NumberBoxButtonHeight}"
HorizontalAlignment="Center"
HorizontalContentAlignment="Center"
IsTabStop="False"
Margin="{StaticResource NumberBoxButtonMargin}"
Padding="{StaticResource NumberBoxButtonPadding}"
VerticalAlignment="Top"
VerticalContentAlignment="Center"
Visibility="Collapsed"
Width="{StaticResource NumberBoxButtonHeight}"
x:Name="PART_InlineIncrementButton">
<controls:SymbolIcon FontSize="{StaticResource NumberBoxButtonIconSize}" Symbol="ChevronUp24" />
</RepeatButton>
<RepeatButton
Background="Transparent"
BorderBrush="Transparent"
FontSize="{StaticResource NumberBoxButtonIconSize}"
Foreground="{DynamicResource TextFillColorSecondaryBrush}"
Height="{StaticResource NumberBoxButtonHeight}"
HorizontalAlignment="Center"
HorizontalContentAlignment="Center"
IsTabStop="False"
Margin="{StaticResource NumberBoxButtonMargin}"
Padding="{StaticResource NumberBoxButtonPadding}"
VerticalAlignment="Top"
VerticalContentAlignment="Center"
Visibility="Collapsed"
Width="{StaticResource NumberBoxButtonHeight}"
x:Name="PART_InlineDecrementButton">
<controls:SymbolIcon FontSize="{StaticResource NumberBoxButtonIconSize}" Symbol="ChevronDown24" />
</RepeatButton>
</StackPanel>
<ContentControl
Content="{TemplateBinding Icon}"
FontSize="16"
Foreground="{TemplateBinding Foreground}"
Grid.Column="3"
IsTabStop="False"
Margin="{StaticResource NumberBoxRightIconMargin}"
Padding="0"
VerticalAlignment="Top"
x:Name="ControlIconRight" />
</Grid>
</Border>
<!-- The Accent Border is a separate element so that changes to the border thickness do not affect the position of the element -->
<Border
BorderBrush="{DynamicResource ControlStrokeColorDefaultBrush}"
BorderThickness="{StaticResource NumberBoxAccentBorderThemeThickness}"
CornerRadius="{TemplateBinding Border.CornerRadius}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
x:Name="AccentBorder" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="CurrentPlaceholderEnabled" Value="False">
<Setter Property="Visibility" TargetName="PlaceholderTextBox" Value="Collapsed" />
</Trigger>
<Trigger Property="ShowClearButton" Value="False">
<Setter Property="Visibility" TargetName="PART_ClearButton" Value="Collapsed" />
<Setter Property="Margin" TargetName="PART_ClearButton" Value="0" />
</Trigger>
<Trigger Property="ClearButtonEnabled" Value="False">
<Setter Property="Visibility" TargetName="PART_ClearButton" Value="Collapsed" />
<Setter Property="Margin" TargetName="PART_ClearButton" Value="0" />
</Trigger>
<Trigger Property="SpinButtonPlacementMode" Value="Hidden">
<Setter Property="Margin" TargetName="PART_InlineIncrementButton" Value="0" />
<Setter Property="Margin" TargetName="PART_InlineDecrementButton" Value="0" />
</Trigger>
<Trigger Property="SpinButtonPlacementMode" Value="Inline">
<Setter Property="Visibility" TargetName="PART_InlineIncrementButton" Value="Visible" />
<Setter Property="Visibility" TargetName="PART_InlineDecrementButton" Value="Visible" />
</Trigger>
<Trigger Property="IconPlacement" Value="Left">
<Setter Property="Visibility" TargetName="ControlIconRight" Value="Collapsed" />
<Setter Property="Margin" TargetName="ControlIconRight" Value="0" />
</Trigger>
<Trigger Property="IconPlacement" Value="Right">
<Setter Property="Visibility" TargetName="ControlIconLeft" Value="Collapsed" />
<Setter Property="Margin" TargetName="ControlIconLeft" Value="0" />
</Trigger>
<Trigger Property="Icon" Value="{x:Null}">
<Setter Property="Visibility" TargetName="ControlIconRight" Value="Collapsed" />
<Setter Property="Margin" TargetName="ControlIconRight" Value="0" />
<Setter Property="Visibility" TargetName="ControlIconLeft" Value="Collapsed" />
<Setter Property="Margin" TargetName="ControlIconLeft" Value="0" />
</Trigger>
<Trigger Property="IsFocused" Value="True">
<Setter Property="BorderThickness" TargetName="AccentBorder" Value="0,0,0,2" />
<Setter Property="BorderBrush" TargetName="AccentBorder" Value="{DynamicResource SystemFillColorAttentionBrush}" />
<Setter Property="Background" TargetName="ContentBorder" Value="{DynamicResource ControlFillColorInputActiveBrush}" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsEnabled" Value="True" />
<Condition Property="IsMouseOver" Value="True" />
<Condition Property="IsFocused" Value="False" />
</MultiTrigger.Conditions>
<Setter Property="Background" TargetName="ContentBorder" Value="{DynamicResource ControlFillColorSecondaryBrush}" />
</MultiTrigger>
<Trigger Property="IsReadOnly" Value="True">
<Setter Property="SpinButtonPlacementMode" Value="Hidden" />
<Setter Property="Visibility" TargetName="PART_ClearButton" Value="Collapsed" />
<Setter Property="Margin" TargetName="PART_ClearButton" Value="0" />
</Trigger>
<Trigger Property="IsEnabled" Value="True">
<Setter Property="Cursor" TargetName="TextContentArea" Value="IBeam" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Cursor" TargetName="TextContentArea" Value="Arrow" />
<Setter Property="Background" TargetName="ContentBorder" Value="{DynamicResource ControlFillColorDisabledBrush}" />
<Setter Property="BorderBrush" TargetName="ContentBorder" Value="{DynamicResource ControlStrokeColorDefaultBrush}" />
<Setter Property="BorderBrush" TargetName="AccentBorder" Value="{DynamicResource ControlStrokeColorDefaultBrush}" />
<Setter Property="Foreground" TargetName="ControlIconLeft" Value="{DynamicResource TextFillColorDisabledBrush}" />
<Setter Property="Foreground" TargetName="ControlIconRight" Value="{DynamicResource TextFillColorDisabledBrush}" />
<Setter Property="Foreground" TargetName="PlaceholderTextBox" Value="{DynamicResource TextFillColorDisabledBrush}" />
<Setter Property="Foreground" Value="{DynamicResource TextFillColorDisabledBrush}" />
<Setter Property="ClearButtonEnabled" Value="False" />
<Setter Property="SpinButtonPlacementMode" Value="Hidden" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style BasedOn="{StaticResource DefaultUiNumberBoxStyle}" TargetType="{x:Type controls:NumberBox}" />
</ResourceDictionary>