AutoCompleteTextBoxBaseStyle.xaml 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  2. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  3. xmlns:hc="clr-namespace:HandyControl.Controls">
  4. <Style x:Key="AutoCompleteTextBoxItemBaseStyle" TargetType="ComboBoxItem">
  5. <Setter Property="Padding" Value="{StaticResource DefaultControlPadding}"/>
  6. <Setter Property="SnapsToDevicePixels" Value="True"/>
  7. <Setter Property="Background" Value="Transparent"/>
  8. <Setter Property="BorderBrush" Value="Transparent"/>
  9. <Setter Property="BorderThickness" Value="0"/>
  10. <Setter Property="MinHeight" Value="{StaticResource DefaultControlHeight}"/>
  11. <Setter Property="Focusable" Value="False"/>
  12. <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
  13. <Setter Property="Template">
  14. <Setter.Value>
  15. <ControlTemplate TargetType="ComboBoxItem">
  16. <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
  17. <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
  18. </Border>
  19. <ControlTemplate.Triggers>
  20. <MultiTrigger>
  21. <MultiTrigger.Conditions>
  22. <Condition Property="IsSelected" Value="False"/>
  23. <Condition Property="IsMouseOver" Value="True"/>
  24. </MultiTrigger.Conditions>
  25. <Setter Property="Background" TargetName="Bd" Value="{DynamicResource SecondaryRegionBrush}"/>
  26. </MultiTrigger>
  27. <Trigger Property="IsSelected" Value="True">
  28. <Setter Property="Background" TargetName="Bd" Value="{DynamicResource PrimaryBrush}"/>
  29. <Setter Property="Foreground" Value="White"/>
  30. </Trigger>
  31. </ControlTemplate.Triggers>
  32. </ControlTemplate>
  33. </Setter.Value>
  34. </Setter>
  35. </Style>
  36. <Style x:Key="AutoCompleteTextBoxBaseStyle" TargetType="hc:AutoCompleteTextBox">
  37. <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
  38. <Setter Property="Background" Value="{DynamicResource RegionBrush}"/>
  39. <Setter Property="hc:BorderElement.CornerRadius" Value="{StaticResource DefaultCornerRadius}"/>
  40. <Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}"/>
  41. <Setter Property="Foreground" Value="{DynamicResource PrimaryTextBrush}"/>
  42. <Setter Property="BorderThickness" Value="1"/>
  43. <Setter Property="CaretBrush" Value="{DynamicResource PrimaryTextBrush}"/>
  44. <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
  45. <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
  46. <Setter Property="MinHeight" Value="{StaticResource DefaultControlHeight}"/>
  47. <Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
  48. <Setter Property="ScrollViewer.PanningMode" Value="Both"/>
  49. <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
  50. <Setter Property="Padding" Value="{StaticResource DefaultInputPadding}"/>
  51. <Setter Property="VerticalContentAlignment" Value="Center"/>
  52. <Setter Property="Validation.ErrorTemplate" Value="{x:Null}"/>
  53. <Setter Property="ItemContainerStyle" Value="{StaticResource AutoCompleteTextBoxItemBaseStyle}"/>
  54. <Setter Property="IsTabStop" Value="false"/>
  55. <Setter Property="hc:Empty.ShowEmpty" Value="True"/>
  56. <Setter Property="Template">
  57. <Setter.Value>
  58. <ControlTemplate TargetType="hc:AutoCompleteTextBox">
  59. <hc:SimplePanel>
  60. <Border CornerRadius="{Binding Path=(hc:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent}}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="true">
  61. <TextBox x:Name="PART_SearchTextBox" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" IsReadOnly="{Binding IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" CaretBrush="{TemplateBinding CaretBrush}" Padding="{TemplateBinding Padding}" Style="{StaticResource ComboBoxEditableTextBox}"/>
  62. </Border>
  63. <Popup x:Name="PART_Popup" AllowsTransparency="true" IsOpen="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Margin="1" PopupAnimation="{StaticResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom">
  64. <Border BorderThickness="0,1,0,0" Effect="{StaticResource EffectShadow2}" Margin="8,0,8,8" CornerRadius="{Binding Path=(hc:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent}}" x:Name="dropDownBorder" MinWidth="{Binding ActualWidth, ElementName=toggleButton}" MaxHeight="{TemplateBinding MaxDropDownHeight}" BorderBrush="{DynamicResource BorderBrush}" Background="{DynamicResource RegionBrush}">
  65. <hc:ToggleBlock IsChecked="{Binding HasItems,RelativeSource={RelativeSource TemplatedParent},Mode=OneWay}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch">
  66. <hc:ToggleBlock.CheckedContent>
  67. <ScrollViewer Margin="0,4">
  68. <ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
  69. </ScrollViewer>
  70. </hc:ToggleBlock.CheckedContent>
  71. <hc:ToggleBlock.UnCheckedContent>
  72. <hc:Empty/>
  73. </hc:ToggleBlock.UnCheckedContent>
  74. </hc:ToggleBlock>
  75. </Border>
  76. </Popup>
  77. </hc:SimplePanel>
  78. <ControlTemplate.Triggers>
  79. <Trigger Property="HasItems" Value="false">
  80. <Setter Property="Height" TargetName="dropDownBorder" Value="95"/>
  81. </Trigger>
  82. <Trigger Property="hc:DropDownElement.ConsistentWidth" Value="True">
  83. <Setter Property="MaxWidth" TargetName="dropDownBorder" Value="{Binding ActualWidth, ElementName=PART_SearchTextBox}"/>
  84. <Setter Property="MinWidth" TargetName="dropDownBorder" Value="{Binding ActualWidth, ElementName=PART_SearchTextBox}"/>
  85. </Trigger>
  86. <Trigger Property="hc:DropDownElement.AutoWidth" Value="True">
  87. <Setter Property="MaxWidth" TargetName="dropDownBorder" Value="{x:Static system:Double.MaxValue}" />
  88. <Setter Property="MinWidth" TargetName="dropDownBorder" Value="{Binding ActualHeight, ElementName=PART_SearchTextBox}" />
  89. </Trigger>
  90. <Trigger Property="IsMouseOver" Value="true" SourceName="PART_SearchTextBox">
  91. <Setter Property="BorderBrush" Value="{DynamicResource SecondaryBorderBrush}"/>
  92. </Trigger>
  93. <MultiTrigger>
  94. <MultiTrigger.Conditions>
  95. <Condition Property="IsMouseOver" Value="true"/>
  96. <Condition Property="IsFocused" Value="false" SourceName="PART_SearchTextBox"/>
  97. </MultiTrigger.Conditions>
  98. <Setter Property="BorderBrush" Value="{DynamicResource SecondaryBorderBrush}"/>
  99. </MultiTrigger>
  100. <Trigger Property="IsFocused" Value="True" SourceName="PART_SearchTextBox">
  101. <Setter Property="BorderBrush" Value="{DynamicResource PrimaryBrush}"/>
  102. </Trigger>
  103. <Trigger Property="IsEnabled" Value="false">
  104. <Setter Property="Opacity" Value="0.4"/>
  105. </Trigger>
  106. </ControlTemplate.Triggers>
  107. </ControlTemplate>
  108. </Setter.Value>
  109. </Setter>
  110. </Style>
  111. </ResourceDictionary>