WritableComboBox.xaml 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <UserControl
  2. x:Class="PDF_Master.CustomControl.WritableComboBox"
  3. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  4. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  5. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  6. xmlns:local="clr-namespace:PDF_Master.CustomControl"
  7. xmlns:help="clr-namespace:PDF_Master.Helper"
  8. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  9. xmlns:convert="clr-namespace:PDF_Master.DataConvert"
  10. d:DesignHeight="24"
  11. d:DesignWidth="200"
  12. Loaded="UserControl_Loaded"
  13. mc:Ignorable="d">
  14. <UserControl.Resources>
  15. <convert:BoolToVisible x:Key="BoolToVisible"/>
  16. <Style x:Key="WarkTextBoxStyle" TargetType="{x:Type TextBox}">
  17. <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
  18. <Setter Property="BorderBrush" Value="#FFABADB3"/>
  19. <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
  20. <Setter Property="BorderThickness" Value="1"/>
  21. <Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
  22. <Setter Property="HorizontalContentAlignment" Value="Left"/>
  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. <ScrollViewer x:Name="PART_ContentHost" Focusable="False" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
  33. <TextBlock x:Name="WARKTEXT" Text="{TemplateBinding Tag}" Foreground="#7F2F2F2F" Visibility="Collapsed" Padding="8,6,0,0"/>
  34. </Grid>
  35. </Border>
  36. <ControlTemplate.Triggers>
  37. <Trigger Property="IsEnabled" Value="False">
  38. <Setter Property="Opacity" TargetName="border" Value="0.56"/>
  39. </Trigger>
  40. <Trigger Property="IsMouseOver" Value="True">
  41. <Setter Property="BorderBrush" TargetName="border" Value="#FF7EB4EA"/>
  42. </Trigger>
  43. <Trigger Property="IsKeyboardFocused" Value="True">
  44. <Setter Property="BorderBrush" TargetName="border" Value="#FF569DE5"/>
  45. </Trigger>
  46. <MultiTrigger>
  47. <MultiTrigger.Conditions>
  48. <Condition Property="Text" Value=""/>
  49. <!--<Condition Property="IsFocused" Value="False"/>-->
  50. </MultiTrigger.Conditions>
  51. <Setter Property="Visibility" TargetName="WARKTEXT" Value="Visible"/>
  52. </MultiTrigger>
  53. </ControlTemplate.Triggers>
  54. </ControlTemplate>
  55. </Setter.Value>
  56. </Setter>
  57. <Style.Triggers>
  58. <MultiTrigger>
  59. <MultiTrigger.Conditions>
  60. <Condition Property="IsInactiveSelectionHighlightEnabled" Value="True"/>
  61. <Condition Property="IsSelectionActive" Value="False"/>
  62. </MultiTrigger.Conditions>
  63. <Setter Property="SelectionBrush" Value="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightBrushKey}}"/>
  64. </MultiTrigger>
  65. </Style.Triggers>
  66. </Style>
  67. </UserControl.Resources>
  68. <Grid>
  69. <ComboBox
  70. x:Name="writableComboBox"
  71. Grid.Column="1"
  72. MinWidth="58"
  73. MinHeight="24"
  74. MouseLeave="writableComboBox_MouseLeave"
  75. MouseEnter="writableComboBox_MouseEnter"
  76. VerticalContentAlignment="Center"
  77. SelectedIndex="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:WritableComboBox}, Path=SelectedIndex}"
  78. SelectionChanged="writableComboBox_SelectionChanged"
  79. Visibility="Visible">
  80. <ComboBoxItem x:Name="AllPageItem" Tag="AllPage" Visibility="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:WritableComboBox}, Path=IsAllPageVisible}"/>
  81. <ComboBoxItem x:Name="OddPageItem" Tag="OddPage"/>
  82. <ComboBoxItem x:Name="EvenPageItem" IsEnabled="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:WritableComboBox}, Path=EvenPageIsEnabled}" Tag="EvenPage"/>
  83. <ComboBoxItem x:Name="CustomPageItem" Tag="CustomPage"/>
  84. </ComboBox>
  85. <Border MinWidth="58" Grid.Column="1"
  86. MinHeight="24" BorderBrush="{StaticResource color.field.border.focus}" Effect="{StaticResource shadow.blue-0-4}" Visibility="{Binding ElementName=writableTextBox, Path=IsFocused, Converter={StaticResource BoolToVisible}}" BorderThickness="1" CornerRadius="4" Panel.ZIndex="1">
  87. </Border>
  88. <Border x:Name="ErrorBorder" MinWidth="58" Grid.Column="1"
  89. MinHeight="24" BorderBrush="{StaticResource color.field.border.error}" Effect="{StaticResource shadow.error.s}" Visibility="Collapsed" BorderThickness="1" CornerRadius="4" Panel.ZIndex="2">
  90. </Border>
  91. <TextBox
  92. x:Name="writableTextBox"
  93. Grid.Column="0"
  94. MinHeight="{Binding ElementName=writableComboBox, Path=MinHeight}"
  95. BorderBrush="{x:Null}"
  96. BorderThickness="0"
  97. Margin="2"
  98. HorizontalAlignment="Left"
  99. VerticalContentAlignment="Center"
  100. Panel.ZIndex="2"
  101. GotFocus="writableTextBox_GotFocus"
  102. LostFocus="writableTextBox_LostFocus"
  103. PreviewKeyDown="writableTextBox_PreviewKeyDown"
  104. InputMethod.IsInputMethodEnabled="False"
  105. PreviewTextInput="writableTextBox_PreviewTextInput"
  106. Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:WritableComboBox}, Path=Text}"
  107. TextChanged="writableTextBox_TextChange"
  108. Visibility="Hidden" Style="{StaticResource WarkTextBoxStyle}" Tag="例如1,3-5,10">
  109. <!--<TextBox.CaretBrush>
  110. <SolidColorBrush Color="#FF7EB4EA"/>
  111. </TextBox.CaretBrush>-->
  112. </TextBox>
  113. </Grid>
  114. </UserControl>