NumericUpDownControl.xaml 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <UserControl x:Class="Compdfkit_Tools.Common.NumericUpDownControl"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  5. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  6. xmlns:local="clr-namespace:Compdfkit_Tools.Common"
  7. x:Name="UserControl"
  8. mc:Ignorable="d"
  9. d:DesignHeight="30" d:DesignWidth="100">
  10. <UserControl.Resources>
  11. <SolidColorBrush x:Key="TextBox.Static.Border" Color="#FFABAdB3"/>
  12. <SolidColorBrush x:Key="TextBox.MouseOver.Border" Color="#FF7EB4EA"/>
  13. <SolidColorBrush x:Key="TextBox.Focus.Border" Color="#FF569DE5"/>
  14. <Style x:Key="ClearButton" TargetType="{x:Type Button}">
  15. <Setter Property="Background" Value="Transparent"></Setter>
  16. <Setter Property="BorderBrush" Value="Transparent"></Setter>
  17. <Setter Property="BorderThickness" Value="0"></Setter>
  18. <Setter Property="Template">
  19. <Setter.Value>
  20. <ControlTemplate TargetType="Button">
  21. <Border Name="border" BorderThickness="0" BorderBrush="Black" Background="{TemplateBinding Background}">
  22. <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
  23. </Border>
  24. <ControlTemplate.Triggers>
  25. <Trigger Property="IsMouseOver" Value="True">
  26. <Setter Property="Background" Value="#F0F0F0" />
  27. </Trigger>
  28. <Trigger Property="IsPressed" Value="True">
  29. <Setter Property="Background" Value="#AAAAAA" />
  30. </Trigger>
  31. <Trigger Property="IsEnabled" Value="False">
  32. <Setter Property="Opacity" Value="0.5" />
  33. </Trigger>
  34. </ControlTemplate.Triggers>
  35. </ControlTemplate>
  36. </Setter.Value>
  37. </Setter>
  38. </Style>
  39. <Style x:Key="NumericUpDownStyle" TargetType="{x:Type TextBox}">
  40. <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
  41. <Setter Property="BorderBrush" Value="Transparent"/>
  42. <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
  43. <Setter Property="BorderThickness" Value="1"/>
  44. <Setter Property="HorizontalContentAlignment" Value="Left"/>
  45. <Setter Property="VerticalContentAlignment" Value="Center"/>
  46. <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
  47. <Setter Property="AllowDrop" Value="true"/>
  48. <Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
  49. <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
  50. <Setter Property="Template">
  51. <Setter.Value>
  52. <ControlTemplate TargetType="{x:Type TextBox}">
  53. <Border BorderThickness="1" BorderBrush="{StaticResource TextBox.Static.Border}">
  54. <Grid>
  55. <Grid.ColumnDefinitions>
  56. <ColumnDefinition></ColumnDefinition>
  57. <ColumnDefinition Width="30"></ColumnDefinition>
  58. <ColumnDefinition Width="20"></ColumnDefinition>
  59. </Grid.ColumnDefinitions>
  60. <ScrollViewer Grid.Column="0" x:Name="PART_ContentHost" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
  61. <TextBlock Grid.Column="1" Text="{Binding Unit, RelativeSource={RelativeSource AncestorType=UserControl}}" VerticalAlignment="Center" HorizontalAlignment="Left"/>
  62. <Grid Grid.Column="2">
  63. <Grid.RowDefinitions>
  64. <RowDefinition></RowDefinition>
  65. <RowDefinition></RowDefinition>
  66. </Grid.RowDefinitions>
  67. <Button x:Name="UpButton" Style="{StaticResource ClearButton}" Click="UpButton_Click">
  68. <Button.Content>
  69. <Path Fill="#CDCDCD" Grid.Column="1" Stroke="#A0A2AE" Height="4.8" Width="7.38" Stretch="Fill">
  70. <Path.Data>
  71. <PathGeometry Figures="M511.99386 361.932146L130.652665 743.283574c-14.944364 14.95869-39.187511 14.95869-54.14313 0-14.95869-14.95562-14.95869-39.187511 0-54.143131l408.411736-408.426063c14.95869-14.95562 39.187511-14.95562 54.144155 0l408.426063 408.426063c7.478322 7.478322 11.217483 17.275455 11.217482 27.072589 0 9.79611-3.739161 19.59222-11.217482 27.070542-14.95562 14.95869-39.187511 14.95869-54.143131 0L511.99386 361.932146z" ></PathGeometry>
  72. </Path.Data>
  73. </Path>
  74. </Button.Content>
  75. </Button>
  76. <Button x:Name="DownButton" Style="{StaticResource ClearButton}" Grid.Row="1" Click="DownButton_Click">
  77. <Button.Content>
  78. <Path Fill="#CDCDCD" Grid.Column="1" Stroke="#A0A2AE" Height="4.8" Width="7.38" Stretch="Fill">
  79. <Path.Data>
  80. <PathGeometry Figures="M917.284001 297.722752c-5.406127-5.437849-13.06762-8.396227-21.479197-8.396227-9.611915 0-18.953677 3.844561-25.713638 10.543124L511.980046 659.992589 153.873018 299.91672c-6.729262-6.745634-16.072047-10.619872-25.654286-10.619872-8.470929 0-16.131399 2.989077-21.598924 8.457626-12.301164 12.435217-11.32493 33.69031 2.192945 47.312562l376.764969 378.821815c6.758937 6.788613 15.860223 10.723226 25.052582 10.8143l3.425006 0c8.981559-0.301875 17.814738-4.205788 24.423249-10.8143l376.733247-378.852514C928.728658 331.382363 929.690566 310.113967 917.284001 297.722752" ></PathGeometry>
  81. </Path.Data>
  82. </Path>
  83. </Button.Content>
  84. </Button>
  85. </Grid>
  86. </Grid>
  87. </Border>
  88. <ControlTemplate.Triggers>
  89. <Trigger Property="IsEnabled" Value="False">
  90. <Setter Property="Opacity" Value="0.5" />
  91. </Trigger>
  92. </ControlTemplate.Triggers>
  93. </ControlTemplate>
  94. </Setter.Value>
  95. </Setter>
  96. </Style>
  97. </UserControl.Resources>
  98. <Grid>
  99. <TextBox x:Name="TextBox"
  100. Style="{StaticResource NumericUpDownStyle}"
  101. InputMethod.IsInputMethodEnabled="False"
  102. PreviewTextInput="TextBox_PreviewTextInput"
  103. PreviewKeyDown="TextBox_PreviewKeyDown"
  104. TextChanged="TextBox_TextChanged">
  105. <TextBox.Text>
  106. <Binding Path="Text" RelativeSource="{RelativeSource AncestorType=UserControl}" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
  107. <Binding.ValidationRules>
  108. <local:CustomValidationRule x:Name="Validator"/>
  109. </Binding.ValidationRules>
  110. </Binding>
  111. </TextBox.Text>
  112. </TextBox>
  113. </Grid>
  114. </UserControl>