NumericUpDownControl.xaml 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. mc:Ignorable="d"
  8. d:DesignHeight="30" d:DesignWidth="100">
  9. <UserControl.Resources>
  10. <SolidColorBrush x:Key="TextBox.Static.Border" Color="#FFABAdB3"/>
  11. <SolidColorBrush x:Key="TextBox.MouseOver.Border" Color="#FF7EB4EA"/>
  12. <SolidColorBrush x:Key="TextBox.Focus.Border" Color="#FF569DE5"/>
  13. <Style x:Key="ClearButton" TargetType="{x:Type Button}">
  14. <Setter Property="Background" Value="Transparent"></Setter>
  15. <Setter Property="BorderBrush" Value="Transparent"></Setter>
  16. <Setter Property="BorderThickness" Value="0"></Setter>
  17. <Setter Property="Template">
  18. <Setter.Value>
  19. <ControlTemplate TargetType="Button">
  20. <Border Name="border" BorderThickness="0" BorderBrush="Black" Background="{TemplateBinding Background}">
  21. <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
  22. </Border>
  23. <ControlTemplate.Triggers>
  24. <Trigger Property="IsMouseOver" Value="True">
  25. <Setter Property="Background" Value="#F0F0F0" />
  26. </Trigger>
  27. <Trigger Property="IsPressed" Value="True">
  28. <Setter Property="Background" Value="#AAAAAA" />
  29. </Trigger>
  30. </ControlTemplate.Triggers>
  31. </ControlTemplate>
  32. </Setter.Value>
  33. </Setter>
  34. </Style>
  35. <Style x:Key="NumericUpDownStyle" TargetType="{x:Type TextBox}">
  36. <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
  37. <Setter Property="BorderBrush" Value="Transparent"/>
  38. <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
  39. <Setter Property="BorderThickness" Value="1"/>
  40. <Setter Property="HorizontalContentAlignment" Value="Left"/>
  41. <Setter Property="VerticalContentAlignment" Value="Center"/>
  42. <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
  43. <Setter Property="AllowDrop" Value="true"/>
  44. <Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
  45. <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
  46. <Setter Property="Template">
  47. <Setter.Value>
  48. <ControlTemplate TargetType="{x:Type TextBox}">
  49. <Border BorderThickness="1" BorderBrush="{StaticResource TextBox.Static.Border}">
  50. <Grid>
  51. <Grid.ColumnDefinitions>
  52. <ColumnDefinition></ColumnDefinition>
  53. <ColumnDefinition Width="30"></ColumnDefinition>
  54. <ColumnDefinition Width="20"></ColumnDefinition>
  55. </Grid.ColumnDefinitions>
  56. <ScrollViewer Grid.Column="0" x:Name="PART_ContentHost" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
  57. <TextBlock Grid.Column="1" Text="{Binding Unit, RelativeSource={RelativeSource AncestorType=UserControl}}" VerticalAlignment="Center" Margin="0,0,15,0"/>
  58. <Grid Grid.Column="2">
  59. <Grid.RowDefinitions>
  60. <RowDefinition></RowDefinition>
  61. <RowDefinition></RowDefinition>
  62. </Grid.RowDefinitions>
  63. <Button x:Name="UpButton" Style="{StaticResource ClearButton}" Click="UpButton_Click">
  64. <Button.Content>
  65. <Path Fill="#CDCDCD" Grid.Column="1" Stroke="#A0A2AE" Height="4.8" Width="7.38" Stretch="Fill">
  66. <Path.Data>
  67. <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>
  68. </Path.Data>
  69. </Path>
  70. </Button.Content>
  71. </Button>
  72. <Button x:Name="DownButton" Style="{StaticResource ClearButton}" Grid.Row="1" Click="DownButton_Click">
  73. <Button.Content>
  74. <Path Fill="#CDCDCD" Grid.Column="1" Stroke="#A0A2AE" Height="4.8" Width="7.38" Stretch="Fill">
  75. <Path.Data>
  76. <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>
  77. </Path.Data>
  78. </Path>
  79. </Button.Content>
  80. </Button>
  81. </Grid>
  82. </Grid>
  83. </Border>
  84. </ControlTemplate>
  85. </Setter.Value>
  86. </Setter>
  87. </Style>
  88. </UserControl.Resources>
  89. <Grid>
  90. <TextBox x:Name="TextBox" Text="{Binding Text, RelativeSource={RelativeSource AncestorType=UserControl}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource NumericUpDownStyle}" InputMethod.IsInputMethodEnabled="False" PreviewTextInput="TextBox_PreviewTextInput" PreviewKeyDown="TextBox_PreviewKeyDown" TextChanged="TextBox_TextChanged"></TextBox>
  91. </Grid>
  92. </UserControl>