feat: add style.

This commit is contained in:
rabbitism
2023-02-24 23:57:41 +08:00
parent 573e3ada21
commit db4db9f1fe
9 changed files with 167 additions and 48 deletions

View File

@@ -10,78 +10,96 @@
</Design.PreviewWith>
<ControlTheme x:Key="{x:Type u:IPv4Box}" TargetType="{x:Type u:IPv4Box}">
<Setter Property="u:IPv4Box.Focusable" Value="True" />
<Setter Property="u:IPv4Box.ShowLeadingZero" Value="True" />
<Setter Property="u:IPv4Box.TextAlignment" Value="Center" />
<Setter Property="u:IPv4Box.HorizontalAlignment" Value="Left" />
<Setter Property="u:IPv4Box.CornerRadius" Value="{DynamicResource IPv4BoxCornerRadius}" />
<Setter Property="u:IPv4Box.Background" Value="{DynamicResource IPv4BoxBackground}" />
<Setter Property="u:IPv4Box.MinHeight" Value="{DynamicResource IPv4BoxDefaultMinHeight}" />
<Setter Property="u:IPv4Box.BorderThickness" Value="{DynamicResource IPv4BoxBorderThickness}" />
<Setter Property="u:IPv4Box.SelectionBrush" Value="{DynamicResource IPv4BoxSelectionBrush}" />
<Setter Property="u:IPv4Box.SelectionForegroundBrush" Value="{DynamicResource IPv4BoxSelectionForeground}" />
<Setter Property="u:IPv4Box.CaretBrush" Value="{DynamicResource IPv4BoxCaretBrush}" />
<Setter Property="u:IPv4Box.Template">
<ControlTemplate TargetType="u:IPv4Box">
<Border
Name="PART_Border"
MinHeight="30"
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
Background="Transparent"
BorderBrush="Black"
BorderThickness="1"
CornerRadius="3">
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}">
<Grid Width="{TemplateBinding Width}" ColumnDefinitions="1*, Auto, 1*, Auto, 1*, Auto, 1*">
<TextPresenter
Name="{x:Static u:IPv4Box.PART_FirstTextPresenter}"
Grid.Column="0"
MinWidth="5"
MinWidth="8"
VerticalAlignment="Center"
CaretBrush="{TemplateBinding CaretBrush}"
Cursor="IBeam"
SelectionBrush="Blue"
SelectionForegroundBrush="White"
Text="123"
TextAlignment="Center" />
SelectionBrush="{TemplateBinding SelectionBrush}"
SelectionForegroundBrush="{TemplateBinding SelectionForegroundBrush}"
TextAlignment="{TemplateBinding TextAlignment}" />
<TextBlock
Grid.Column="1"
Margin="0,4"
VerticalAlignment="Bottom"
VerticalAlignment="Center"
Focusable="False"
Text="." />
<TextPresenter
Name="{x:Static u:IPv4Box.PART_SecondTextPresenter}"
Grid.Column="2"
MinWidth="5"
MinWidth="8"
VerticalAlignment="Center"
CaretBrush="{TemplateBinding CaretBrush}"
Cursor="IBeam"
SelectionBrush="Blue"
SelectionForegroundBrush="White"
Text="123"
TextAlignment="Center" />
SelectionBrush="{TemplateBinding SelectionBrush}"
SelectionForegroundBrush="{TemplateBinding SelectionForegroundBrush}"
TextAlignment="{TemplateBinding TextAlignment}" />
<TextBlock
Grid.Column="3"
Margin="0,4"
VerticalAlignment="Bottom"
VerticalAlignment="Center"
Text="." />
<TextPresenter
Name="{x:Static u:IPv4Box.PART_ThirdTextPresenter}"
Grid.Column="4"
MinWidth="5"
MinWidth="8"
VerticalAlignment="Center"
CaretBrush="{TemplateBinding CaretBrush}"
Cursor="IBeam"
SelectionBrush="Blue"
SelectionForegroundBrush="White"
TextAlignment="Center" />
SelectionBrush="{TemplateBinding SelectionBrush}"
SelectionForegroundBrush="{TemplateBinding SelectionForegroundBrush}"
TextAlignment="{TemplateBinding TextAlignment}" />
<TextBlock
Grid.Column="5"
Margin="0,4"
VerticalAlignment="Bottom"
VerticalAlignment="Center"
Text="." />
<TextPresenter
Name="{x:Static u:IPv4Box.PART_FourthTextPresenter}"
Grid.Column="6"
MinWidth="5"
MinWidth="8"
VerticalAlignment="Center"
CaretBrush="{TemplateBinding CaretBrush}"
Cursor="IBeam"
SelectionBrush="Blue"
SelectionForegroundBrush="White"
TextAlignment="Center" />
SelectionBrush="{TemplateBinding SelectionBrush}"
SelectionForegroundBrush="{TemplateBinding SelectionForegroundBrush}"
TextAlignment="{TemplateBinding TextAlignment}" />
</Grid>
</Border>
</ControlTemplate>
</Setter>
<Style Selector="^:focus-within /template/ Border#PART_Border">
<Setter Property="BorderBrush" Value="Red" />
<Style Selector="^:pointerover /template/ Border#PART_Border">
<Setter Property="Border.Background" Value="{DynamicResource IPv4BoxPointeroverBackground}" />
</Style>
<Style Selector="^:pressed /template/ Border#PART_Border">
<Setter Property="Border.Background" Value="{DynamicResource IPv4BoxPressedBackground}" />
</Style>
<Style Selector="^:focus-within">
<Setter Property="Border.BorderBrush" Value="{DynamicResource IPv4BoxFocusBorderBrush}" />
</Style>
<Style Selector="^:disabled">
<Setter Property="Border.Background" Value="{DynamicResource IPv4BoxDisabledBackground}" />
</Style>
</ControlTheme>
</ResourceDictionary>