SearchComboBox.xaml 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <ResourceDictionary
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:wpf="clr-namespace:FWindSoft.Wpf"
  5. xmlns:local="clr-namespace:FWindSoft.Wpf.Controls">
  6. <LinearGradientBrush x:Key="ActiveButtonBrush" StartPoint="0,0" EndPoint="0,1">
  7. <LinearGradientBrush.GradientStops>
  8. <GradientStop Color="#EAF6FD" Offset="0.15" />
  9. <GradientStop Color="#D9F0FC" Offset=".5" />
  10. <GradientStop Color="#BEE6FD" Offset=".5" />
  11. <GradientStop Color="#A7D9F5" Offset="1" />
  12. </LinearGradientBrush.GradientStops>
  13. </LinearGradientBrush>
  14. <SolidColorBrush x:Key="ActiveBorderBrush" Color="DarkBlue" />
  15. <!-- Style for a ListBoxItem displayed inside the embedded list box, to make it a check box when mode = multiple. -->
  16. <Style x:Key="CheckBoxedItemStyleKey" TargetType="{x:Type ListBoxItem}">
  17. <Setter Property="Template">
  18. <Setter.Value>
  19. <ControlTemplate TargetType="{x:Type ListBoxItem}">
  20. <Border Background="Transparent">
  21. <CheckBox Focusable="false"
  22. Foreground="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Foreground}"
  23. BorderBrush="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}, Path=Foreground}"
  24. Content="{TemplateBinding ContentPresenter.Content}"
  25. IsChecked="{Binding Path=IsSelected, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"/>
  26. </Border>
  27. </ControlTemplate>
  28. </Setter.Value>
  29. </Setter>
  30. </Style>
  31. <!-- Style for a ListBoxItem displayed inside the embedded list box, when mode = single -->
  32. <Style x:Key="NormalItemStyleKey" TargetType="{x:Type ListBoxItem}">
  33. <Setter Property="Template">
  34. <Setter.Value>
  35. <ControlTemplate TargetType="{x:Type ListBoxItem}">
  36. <Border Name="border"
  37. Margin="0,-1"
  38. Background="{TemplateBinding Background}"
  39. BorderBrush="{TemplateBinding BorderBrush}"
  40. BorderThickness="1"
  41. SnapsToDevicePixels="true">
  42. <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
  43. </Border>
  44. <ControlTemplate.Triggers>
  45. <Trigger Property="IsMouseOver" Value="True">
  46. <Setter Property="BorderBrush" Value="{x:Static SystemColors.HighlightBrush}" />
  47. </Trigger>
  48. <Trigger Property="IsSelected" Value="True">
  49. <Setter Property="Background" Value="{x:Static SystemColors.HighlightBrush}" />
  50. <Setter Property="Foreground" Value="{x:Static SystemColors.HighlightTextBrush}" />
  51. </Trigger>
  52. </ControlTemplate.Triggers>
  53. </ControlTemplate>
  54. </Setter.Value>
  55. </Setter>
  56. </Style>
  57. <Style x:Key="FocusVisualStyle">
  58. <Setter Property="Control.Template">
  59. <Setter.Value>
  60. <ControlTemplate>
  61. <Border>
  62. <Rectangle
  63. Margin="2"
  64. StrokeThickness="1"
  65. Stroke="#b0000000"
  66. StrokeDashArray="1 2"/>
  67. </Border>
  68. </ControlTemplate>
  69. </Setter.Value>
  70. </Setter>
  71. </Style>
  72. <!-- Template for the toggle button which is the main view of the control -->
  73. <ControlTemplate x:Key="MultiSelectComboBoxToggleButtonTemplate" TargetType="{x:Type Button}">
  74. <Border BorderThickness="{TemplateBinding BorderThickness}"
  75. Background="{TemplateBinding Background}"
  76. BorderBrush="{TemplateBinding BorderBrush}"
  77. SnapsToDevicePixels="true">
  78. <Grid>
  79. <Grid.ColumnDefinitions>
  80. <ColumnDefinition />
  81. <ColumnDefinition Width="Auto"/>
  82. </Grid.ColumnDefinitions>
  83. <ContentPresenter Content="{TemplateBinding Content}" />
  84. <Border Name="arrowBorder" Grid.Column="1" Width="16" BorderBrush="{TemplateBinding BorderBrush}">
  85. <Path HorizontalAlignment="Center" VerticalAlignment="Center"
  86. Fill="{TemplateBinding BorderBrush}" Data="M 0 0 L 7 0 L 3.5 4 Z" />
  87. </Border>
  88. </Grid>
  89. </Border>
  90. <ControlTemplate.Triggers>
  91. <Trigger Property="IsMouseOver" Value="True">
  92. <Setter TargetName="arrowBorder" Property="Background" Value="{StaticResource ActiveButtonBrush}" />
  93. <Setter TargetName="arrowBorder" Property="BorderThickness" Value="1,0,0,0" />
  94. </Trigger>
  95. <!--<Trigger Property="IsChecked" Value="True">
  96. <Setter TargetName="arrowBorder" Property="Background" Value="{StaticResource ActiveButtonBrush}" />
  97. <Setter TargetName="arrowBorder" Property="BorderThickness" Value="1,0,0,0" />
  98. </Trigger>-->
  99. </ControlTemplate.Triggers>
  100. </ControlTemplate>
  101. <ControlTemplate x:Key="SearchComboBoxTemplate" TargetType="{x:Type local:SearchComboBox}">
  102. <Grid >
  103. <Grid.ColumnDefinitions>
  104. <ColumnDefinition Width="*"></ColumnDefinition>
  105. <ColumnDefinition Width="Auto"></ColumnDefinition>
  106. </Grid.ColumnDefinitions>
  107. <TextBox IsReadOnly="{Binding RelativeSource={RelativeSource TemplatedParent},Path=IsReadOnly}" BorderThickness="1,1,0,1" BorderBrush="Black" Name="PART_SearchText" Margin="1,0,0,0" Grid.Column="0" Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Text,Mode=TwoWay}"></TextBox>
  108. <Button Grid.Column="1" Name="PART_Button" IsTabStop="False"
  109. Background="{TemplateBinding Background}"
  110. BorderBrush="{TemplateBinding BorderBrush}"
  111. BorderThickness="{TemplateBinding BorderThickness}"
  112. Template="{StaticResource MultiSelectComboBoxToggleButtonTemplate}"
  113. >
  114. </Button>
  115. <Popup Name="PART_Popup"
  116. StaysOpen="False"
  117. AllowsTransparency="True"
  118. Placement="Bottom"
  119. IsOpen="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsDropDownOpen,Mode=TwoWay}"
  120. FocusManager.IsFocusScope="True"
  121. FocusManager.FocusedElement="{Binding ElementName=List}"
  122. PopupAnimation="Slide">
  123. <Border Name="Shadow"
  124. MaxHeight="{TemplateBinding MaxDropDownHeight}"
  125. MinWidth="{TemplateBinding ActualWidth}">
  126. <Border BorderBrush="{TemplateBinding BorderBrush}"
  127. BorderThickness="{TemplateBinding BorderThickness}"
  128. Background="{TemplateBinding Background}">
  129. <StackPanel>
  130. <ScrollViewer MaxHeight="{TemplateBinding MaxDropDownHeight}" >
  131. <ItemsPresenter x:Name="List" Margin="{TemplateBinding Padding}" KeyboardNavigation.DirectionalNavigation="Contained"
  132. SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
  133. </ScrollViewer>
  134. </StackPanel>
  135. </Border>
  136. </Border>
  137. </Popup>
  138. </Grid>
  139. <ControlTemplate.Triggers>
  140. <Trigger SourceName="PART_Popup" Property="HasDropShadow" Value="true">
  141. <Setter TargetName="Shadow" Property="Margin" Value="0,0,5,5" />
  142. <!--<Setter TargetName="Shadow" Property="Color" Value="#71000000" />-->
  143. </Trigger>
  144. <Trigger Property="IsMouseOver" Value="True">
  145. <Setter Property="BorderBrush" Value="{StaticResource ActiveBorderBrush}" />
  146. </Trigger>
  147. <!--<Trigger SourceName="toggleButton" Property="IsChecked" Value="True">
  148. <Setter Property="BorderBrush" Value="{StaticResource ActiveBorderBrush}" />
  149. </Trigger>-->
  150. </ControlTemplate.Triggers>
  151. </ControlTemplate>
  152. <!-- Style which defines the MultiComboBox -->
  153. <Style TargetType="{x:Type local:SearchComboBox}">
  154. <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
  155. <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
  156. <Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
  157. <Setter Property="MinWidth" Value="120"/>
  158. <Setter Property="MinHeight" Value="20"/>
  159. <Setter Property="Foreground" Value="{x:Static SystemColors.WindowTextBrush}" />
  160. <Setter Property="BorderBrush" Value="{x:Static SystemColors.WindowTextBrush}" />
  161. <Setter Property="Background" Value="{x:Static SystemColors.WindowBrush}" />
  162. <Setter Property="BorderThickness" Value="1" />
  163. <Setter Property="IsTabStop" Value="True" />
  164. <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisualStyle}" />
  165. <Setter Property="Template" Value="{StaticResource SearchComboBoxTemplate}" />
  166. <Setter Property="ItemContainerStyle" Value="{StaticResource NormalItemStyleKey}" />
  167. </Style>
  168. </ResourceDictionary>