DropDownNumberBoxControl.xaml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <UserControl x:Class="ComPDFKit.Controls.Common.DropDownNumberBoxControl"
  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:cpdfcommon="clr-namespace:ComPDFKit.Controls.Common"
  7. mc:Ignorable="d"
  8. d:DesignHeight="30" d:DesignWidth="100">
  9. <UserControl.Resources>
  10. <cpdfcommon:BoolToVisibleConverter x:Key="BoolToVisibleConverter"></cpdfcommon:BoolToVisibleConverter>
  11. <cpdfcommon:BoolToCollapsedConverter x:Key="BoolToCollapsedConverter"></cpdfcommon:BoolToCollapsedConverter>
  12. <SolidColorBrush x:Key="TextBox.Static.Border" Color="#FFABAdB3"/>
  13. <SolidColorBrush x:Key="TextBox.MouseOver.Border" Color="#FF7EB4EA"/>
  14. <SolidColorBrush x:Key="TextBox.Focus.Border" Color="#FF569DE5"/>
  15. <Style x:Key="LimitedNumberBoxWithUnit" TargetType="{x:Type TextBox}">
  16. <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
  17. <Setter Property="BorderBrush" Value="Transparent"/>
  18. <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
  19. <Setter Property="BorderThickness" Value="1"/>
  20. <Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
  21. <Setter Property="HorizontalContentAlignment" Value="Left"/>
  22. <Setter Property="VerticalContentAlignment" Value="Center"/>
  23. <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
  24. <Setter Property="AllowDrop" Value="true"/>
  25. <Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
  26. <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
  27. <Setter Property="Template">
  28. <Setter.Value>
  29. <ControlTemplate TargetType="{x:Type TextBox}">
  30. <Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
  31. <Grid>
  32. <Grid.ColumnDefinitions>
  33. <ColumnDefinition Width="*"/>
  34. <ColumnDefinition Width="20"/>
  35. </Grid.ColumnDefinitions>
  36. <ScrollViewer Grid.Column="0" x:Name="PART_ContentHost" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden" Margin="5,0,0,0"/>
  37. <TextBlock Grid.Column="1" Text="{Binding Unit, RelativeSource={RelativeSource AncestorType=UserControl}}" HorizontalAlignment="Right" VerticalAlignment="Center"/>
  38. </Grid>
  39. </Border>
  40. </ControlTemplate>
  41. </Setter.Value>
  42. </Setter>
  43. </Style>
  44. <Style x:Key="TransparentToggleButton" TargetType="{x:Type ToggleButton}">
  45. <Setter Property="Background" Value="Transparent"/>
  46. <Setter Property="BorderBrush" Value="Transparent"/>
  47. <Setter Property="Template">
  48. <Setter.Value>
  49. <ControlTemplate TargetType="{x:Type ToggleButton}">
  50. <Border x:Name="border"
  51. Background="{TemplateBinding Background}"
  52. BorderBrush="{TemplateBinding BorderBrush}"
  53. BorderThickness="{TemplateBinding BorderThickness}"
  54. Padding="{TemplateBinding Padding}">
  55. <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
  56. VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
  57. RecognizesAccessKey="True"/>
  58. </Border>
  59. <ControlTemplate.Triggers>
  60. <Trigger Property="IsChecked" Value="True">
  61. <Setter TargetName="border" Property="Opacity" Value="0"/>
  62. </Trigger>
  63. <Trigger Property="IsMouseOver" Value="True">
  64. <Setter TargetName="border" Property="Opacity" Value="0"/>
  65. </Trigger>
  66. <Trigger Property="IsPressed" Value="True">
  67. <Setter TargetName="border" Property="Opacity" Value="0"/>
  68. </Trigger>
  69. </ControlTemplate.Triggers>
  70. </ControlTemplate>
  71. </Setter.Value>
  72. </Setter>
  73. </Style>
  74. <Style x:Key="PresetComboBox" TargetType="{x:Type ComboBox}">
  75. <Setter Property="Template">
  76. <Setter.Value>
  77. <ControlTemplate TargetType="{x:Type ComboBox}">
  78. <Border x:Name="border" BorderBrush="{StaticResource TextBox.Static.Border}" BorderThickness="1" Background="#FFFFFF">
  79. <Grid>
  80. <Grid.ColumnDefinitions>
  81. <ColumnDefinition></ColumnDefinition>
  82. <ColumnDefinition Width="15"></ColumnDefinition>
  83. </Grid.ColumnDefinitions>
  84. <Grid Grid.Column="1">
  85. <Path Fill="#CDCDCD" Stroke="#CDCDCD" Grid.Column="1" Height="4.8" Width="7.38" Stretch="Fill" Visibility="{Binding Path=IsDropDownOpen,Converter={StaticResource BoolToCollapsedConverter},RelativeSource={RelativeSource TemplatedParent}}">
  86. <Path.Data>
  87. <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>
  88. </Path.Data>
  89. </Path>
  90. <Path Fill="#CDCDCD" Stroke="#CDCDCD" Grid.Column="1" Height="4.8" Width="7.38" Stretch="Fill" Visibility="{Binding Path=IsDropDownOpen,Converter={StaticResource BoolToVisibleConverter},RelativeSource={RelativeSource TemplatedParent}}">
  91. <Path.Data>
  92. <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>
  93. </Path.Data>
  94. </Path>
  95. </Grid>
  96. <Grid Grid.Column="0" Grid.ColumnSpan="2">
  97. <ToggleButton IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
  98. ClickMode="Press" Style="{StaticResource TransparentToggleButton}"></ToggleButton>
  99. <Popup Name="popup"
  100. IsOpen="{TemplateBinding IsDropDownOpen}"
  101. Placement="Bottom" AllowsTransparency="True" PopupAnimation="Fade" VerticalOffset="1">
  102. <Border MinWidth="{TemplateBinding ActualWidth}"
  103. MaxHeight="{TemplateBinding MaxDropDownHeight}">
  104. <ScrollViewer MaxHeight="{TemplateBinding MaxDropDownHeight}"
  105. HorizontalScrollBarVisibility="Auto"
  106. VerticalScrollBarVisibility="Auto">
  107. <Border BorderBrush ="LightGray" BorderThickness="1">
  108. <StackPanel Background="#FFFFFF" MinHeight="20"
  109. IsItemsHost="True"/>
  110. </Border>
  111. </ScrollViewer>
  112. </Border>
  113. </Popup>
  114. </Grid>
  115. </Grid>
  116. </Border>
  117. <ControlTemplate.Triggers>
  118. <Trigger Property="IsMouseOver" Value="true">
  119. <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource TextBox.MouseOver.Border}"/>
  120. </Trigger>
  121. </ControlTemplate.Triggers>
  122. </ControlTemplate>
  123. </Setter.Value>
  124. </Setter>
  125. </Style>
  126. </UserControl.Resources>
  127. <Grid>
  128. <Grid.ColumnDefinitions>
  129. <ColumnDefinition Width="1*"></ColumnDefinition>
  130. <ColumnDefinition Width="20"></ColumnDefinition>
  131. </Grid.ColumnDefinitions>
  132. <ComboBox Grid.ColumnSpan="2" x:Name="ComboBox" Background="#FFFFFF" Style="{StaticResource PresetComboBox}" SelectionChanged="ComboBox_SelectionChanged" ></ComboBox>
  133. <TextBox x:Name="TextBox" Text="{Binding Text, RelativeSource={RelativeSource AncestorType=UserControl}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource LimitedNumberBoxWithUnit}" HorizontalContentAlignment="Center" InputMethod.IsInputMethodEnabled="False" PreviewTextInput="TextBox_PreviewTextInput" PreviewKeyDown="TextBox_PreviewKeyDown" TextChanged="TextBox_TextChanged" >
  134. </TextBox>
  135. </Grid>
  136. </UserControl>