MultipleSelectionsCombox.xaml 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. <UserControl x:Class="MECF.Framework.UI.Client.Ctrlib.Controls.MultipleSelectionsCombox"
  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:MECF.Framework.UI.Client.Ctrlib.Controls"
  7. mc:Ignorable="d"
  8. d:DesignHeight="450" d:DesignWidth="800">
  9. <UserControl.Resources>
  10. <LinearGradientBrush x:Key="NormalBrush" StartPoint="0,0" EndPoint="0,1">
  11. <GradientBrush.GradientStops>
  12. <GradientStopCollection>
  13. <GradientStop Color="#FFF" Offset="0.0"/>
  14. <GradientStop Color="#CCC" Offset="1.0"/>
  15. </GradientStopCollection>
  16. </GradientBrush.GradientStops>
  17. </LinearGradientBrush>
  18. <LinearGradientBrush x:Key="NormalBorderBrush" StartPoint="0,0" EndPoint="0,1">
  19. <GradientBrush.GradientStops>
  20. <GradientStopCollection>
  21. <GradientStop Color="#CCC" Offset="0.0"/>
  22. <GradientStop Color="#444" Offset="1.0"/>
  23. </GradientStopCollection>
  24. </GradientBrush.GradientStops>
  25. </LinearGradientBrush>
  26. <SolidColorBrush x:Key="GlyphBrush" Color="#444" />
  27. <LinearGradientBrush x:Key="DarkBrush" StartPoint="0,0" EndPoint="0,1">
  28. <GradientBrush.GradientStops>
  29. <GradientStopCollection>
  30. <GradientStop Color="#FFF" Offset="0.0"/>
  31. <GradientStop Color="#AAA" Offset="1.0"/>
  32. </GradientStopCollection>
  33. </GradientBrush.GradientStops>
  34. </LinearGradientBrush>
  35. <LinearGradientBrush x:Key="PressedBrush" StartPoint="0,0" EndPoint="0,1">
  36. <GradientBrush.GradientStops>
  37. <GradientStopCollection>
  38. <GradientStop Color="#BBB" Offset="0.0"/>
  39. <GradientStop Color="#EEE" Offset="0.1"/>
  40. <GradientStop Color="#EEE" Offset="0.9"/>
  41. <GradientStop Color="#FFF" Offset="1.0"/>
  42. </GradientStopCollection>
  43. </GradientBrush.GradientStops>
  44. </LinearGradientBrush>
  45. <SolidColorBrush x:Key="DisabledForegroundBrush" Color="#888" />
  46. <SolidColorBrush x:Key="DisabledBackgroundBrush" Color="#EEE" />
  47. <SolidColorBrush x:Key="WindowBackgroundBrush" Color="#FFF" />
  48. <SolidColorBrush x:Key="SelectedBackgroundBrush" Color="#DDD" />
  49. <SolidColorBrush x:Key="ComboBox.Static.Border" Color="#FFACACAC"/>
  50. <SolidColorBrush x:Key="ComboBox.Static.Editable.Background" Color="#FFFFFFFF"/>
  51. <SolidColorBrush x:Key="ComboBox.Static.Editable.Border" Color="#FFABADB3"/>
  52. <SolidColorBrush x:Key="ComboBox.Static.Editable.Button.Background" Color="Transparent"/>
  53. <SolidColorBrush x:Key="ComboBox.Static.Editable.Button.Border" Color="Transparent"/>
  54. <SolidColorBrush x:Key="ComboBox.MouseOver.Glyph" Color="#FF000000"/>
  55. <LinearGradientBrush x:Key="ComboBox.MouseOver.Background" EndPoint="0,1" StartPoint="0,0">
  56. <GradientStop Color="#FFECF4FC" Offset="0.0"/>
  57. <GradientStop Color="#FFDCECFC" Offset="1.0"/>
  58. </LinearGradientBrush>
  59. <SolidColorBrush x:Key="ComboBox.MouseOver.Border" Color="#FF7EB4EA"/>
  60. <SolidColorBrush x:Key="ComboBox.MouseOver.Editable.Background" Color="#FFFFFFFF"/>
  61. <SolidColorBrush x:Key="ComboBox.MouseOver.Editable.Border" Color="#FF7EB4EA"/>
  62. <LinearGradientBrush x:Key="ComboBox.MouseOver.Editable.Button.Background" EndPoint="0,1" StartPoint="0,0">
  63. <GradientStop Color="#FFEBF4FC" Offset="0.0"/>
  64. <GradientStop Color="#FFDCECFC" Offset="1.0"/>
  65. </LinearGradientBrush>
  66. <SolidColorBrush x:Key="ComboBox.MouseOver.Editable.Button.Border" Color="#FF7EB4EA"/>
  67. <SolidColorBrush x:Key="ComboBox.Pressed.Glyph" Color="#FF000000"/>
  68. <LinearGradientBrush x:Key="ComboBox.Pressed.Background" EndPoint="0,1" StartPoint="0,0">
  69. <GradientStop Color="#FFDAECFC" Offset="0.0"/>
  70. <GradientStop Color="#FFC4E0FC" Offset="1.0"/>
  71. </LinearGradientBrush>
  72. <SolidColorBrush x:Key="ComboBox.Pressed.Border" Color="#FF569DE5"/>
  73. <SolidColorBrush x:Key="ComboBox.Pressed.Editable.Background" Color="#FFFFFFFF"/>
  74. <SolidColorBrush x:Key="ComboBox.Pressed.Editable.Border" Color="#FF569DE5"/>
  75. <LinearGradientBrush x:Key="ComboBox.Pressed.Editable.Button.Background" EndPoint="0,1" StartPoint="0,0">
  76. <GradientStop Color="#FFDAEBFC" Offset="0.0"/>
  77. <GradientStop Color="#FFC4E0FC" Offset="1.0"/>
  78. </LinearGradientBrush>
  79. <SolidColorBrush x:Key="ComboBox.Pressed.Editable.Button.Border" Color="#FF569DE5"/>
  80. <SolidColorBrush x:Key="ComboBox.Disabled.Glyph" Color="#FFBFBFBF"/>
  81. <SolidColorBrush x:Key="ComboBox.Disabled.Background" Color="#FFF0F0F0"/>
  82. <SolidColorBrush x:Key="ComboBox.Disabled.Border" Color="#FFD9D9D9"/>
  83. <SolidColorBrush x:Key="ComboBox.Disabled.Editable.Background" Color="#FFFFFFFF"/>
  84. <SolidColorBrush x:Key="ComboBox.Disabled.Editable.Border" Color="#FFBFBFBF"/>
  85. <SolidColorBrush x:Key="ComboBox.Disabled.Editable.Button.Background" Color="Transparent"/>
  86. <SolidColorBrush x:Key="ComboBox.Disabled.Editable.Button.Border" Color="Transparent"/>
  87. <SolidColorBrush x:Key="ComboBox.Static.Glyph" Color="#FF3C77DD"/>
  88. <ControlTemplate x:Key="ComboBoxTextBox" TargetType="TextBox">
  89. <Border x:Name="PART_ContentHost" Focusable="False" Background="{TemplateBinding Background}" />
  90. </ControlTemplate>
  91. <Style x:Key="ComboBoxToggleButton" TargetType="ToggleButton">
  92. <Setter Property="OverridesDefaultStyle" Value="true"/>
  93. <Setter Property="IsTabStop" Value="false"/>
  94. <Setter Property="Focusable" Value="false"/>
  95. <Setter Property="ClickMode" Value="Press"/>
  96. <Setter Property="Template">
  97. <Setter.Value>
  98. <ControlTemplate TargetType="{x:Type ToggleButton}">
  99. <Border x:Name="templateRoot" CornerRadius="5" BorderBrush="{StaticResource ComboBox.Static.Border}" BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="true" Background="White">
  100. <Border x:Name="splitBorder" BorderBrush="Transparent" BorderThickness="1" HorizontalAlignment="Right" Margin="0,0,2,0" SnapsToDevicePixels="true" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}">
  101. <Path x:Name="arrow" Data="F1 M 0,0 L 3.667,2.66665 L 7.3334,0 L 7.3334,-1.78168 L 3.6667,0.88501 L0,-1.78168 L0,0 Z" Fill="{StaticResource ComboBox.Static.Glyph}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
  102. </Border>
  103. </Border>
  104. <ControlTemplate.Triggers>
  105. <MultiDataTrigger>
  106. <MultiDataTrigger.Conditions>
  107. <Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="true"/>
  108. <Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="false"/>
  109. <Condition Binding="{Binding IsPressed, RelativeSource={RelativeSource Self}}" Value="false"/>
  110. <Condition Binding="{Binding IsEnabled, RelativeSource={RelativeSource Self}}" Value="true"/>
  111. </MultiDataTrigger.Conditions>
  112. <Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.Static.Editable.Background}"/>
  113. <Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.Static.Editable.Border}"/>
  114. <Setter Property="Background" TargetName="splitBorder" Value="{StaticResource ComboBox.Static.Editable.Button.Background}"/>
  115. <Setter Property="BorderBrush" TargetName="splitBorder" Value="{StaticResource ComboBox.Static.Editable.Button.Border}"/>
  116. </MultiDataTrigger>
  117. <Trigger Property="IsMouseOver" Value="true">
  118. <Setter Property="Fill" TargetName="arrow" Value="{StaticResource ComboBox.MouseOver.Glyph}"/>
  119. </Trigger>
  120. <MultiDataTrigger>
  121. <MultiDataTrigger.Conditions>
  122. <Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="true"/>
  123. <Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="false"/>
  124. </MultiDataTrigger.Conditions>
  125. <Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.MouseOver.Background}"/>
  126. <Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.MouseOver.Border}"/>
  127. </MultiDataTrigger>
  128. <MultiDataTrigger>
  129. <MultiDataTrigger.Conditions>
  130. <Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="true"/>
  131. <Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="true"/>
  132. </MultiDataTrigger.Conditions>
  133. <Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.MouseOver.Editable.Background}"/>
  134. <Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.MouseOver.Editable.Border}"/>
  135. <Setter Property="Background" TargetName="splitBorder" Value="{StaticResource ComboBox.MouseOver.Editable.Button.Background}"/>
  136. <Setter Property="BorderBrush" TargetName="splitBorder" Value="{StaticResource ComboBox.MouseOver.Editable.Button.Border}"/>
  137. </MultiDataTrigger>
  138. <Trigger Property="IsPressed" Value="true">
  139. <Setter Property="Fill" TargetName="arrow" Value="{StaticResource ComboBox.Pressed.Glyph}"/>
  140. </Trigger>
  141. <MultiDataTrigger>
  142. <MultiDataTrigger.Conditions>
  143. <Condition Binding="{Binding IsPressed, RelativeSource={RelativeSource Self}}" Value="true"/>
  144. <Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="false"/>
  145. </MultiDataTrigger.Conditions>
  146. <Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.Pressed.Background}"/>
  147. <Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.Pressed.Border}"/>
  148. </MultiDataTrigger>
  149. <MultiDataTrigger>
  150. <MultiDataTrigger.Conditions>
  151. <Condition Binding="{Binding IsPressed, RelativeSource={RelativeSource Self}}" Value="true"/>
  152. <Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="true"/>
  153. </MultiDataTrigger.Conditions>
  154. <Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.Pressed.Editable.Background}"/>
  155. <Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.Pressed.Editable.Border}"/>
  156. <Setter Property="Background" TargetName="splitBorder" Value="{StaticResource ComboBox.Pressed.Editable.Button.Background}"/>
  157. <Setter Property="BorderBrush" TargetName="splitBorder" Value="{StaticResource ComboBox.Pressed.Editable.Button.Border}"/>
  158. </MultiDataTrigger>
  159. <Trigger Property="IsEnabled" Value="false">
  160. <Setter Property="Fill" TargetName="arrow" Value="{StaticResource ComboBox.Disabled.Glyph}"/>
  161. </Trigger>
  162. <MultiDataTrigger>
  163. <MultiDataTrigger.Conditions>
  164. <Condition Binding="{Binding IsEnabled, RelativeSource={RelativeSource Self}}" Value="false"/>
  165. <Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="false"/>
  166. </MultiDataTrigger.Conditions>
  167. <Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.Disabled.Background}"/>
  168. <Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.Disabled.Border}"/>
  169. </MultiDataTrigger>
  170. <MultiDataTrigger>
  171. <MultiDataTrigger.Conditions>
  172. <Condition Binding="{Binding IsEnabled, RelativeSource={RelativeSource Self}}" Value="false"/>
  173. <Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="true"/>
  174. </MultiDataTrigger.Conditions>
  175. <Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.Disabled.Editable.Background}"/>
  176. <Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.Disabled.Editable.Border}"/>
  177. <Setter Property="Background" TargetName="splitBorder" Value="{StaticResource ComboBox.Disabled.Editable.Button.Background}"/>
  178. <Setter Property="BorderBrush" TargetName="splitBorder" Value="{StaticResource ComboBox.Disabled.Editable.Button.Border}"/>
  179. </MultiDataTrigger>
  180. </ControlTemplate.Triggers>
  181. </ControlTemplate>
  182. </Setter.Value>
  183. </Setter>
  184. </Style>
  185. <Style x:Key="{x:Type ComboBoxItem}" TargetType="ComboBoxItem">
  186. <Setter Property="SnapsToDevicePixels" Value="true"/>
  187. <Setter Property="OverridesDefaultStyle" Value="true"/>
  188. <Setter Property="Template">
  189. <Setter.Value>
  190. <ControlTemplate TargetType="ComboBoxItem">
  191. <Border
  192. Name="Border"
  193. Padding="2"
  194. SnapsToDevicePixels="true">
  195. <ContentPresenter />
  196. </Border>
  197. <ControlTemplate.Triggers>
  198. <Trigger Property="IsHighlighted" Value="true">
  199. <Setter TargetName="Border" Property="Background" Value="{StaticResource SelectedBackgroundBrush}"/>
  200. </Trigger>
  201. <Trigger Property="IsEnabled" Value="false">
  202. <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
  203. </Trigger>
  204. </ControlTemplate.Triggers>
  205. </ControlTemplate>
  206. </Setter.Value>
  207. </Setter>
  208. </Style>
  209. </UserControl.Resources>
  210. <Grid>
  211. <ComboBox x:Name="CheckableCombo">
  212. <ComboBox.ItemTemplate>
  213. <HierarchicalDataTemplate>
  214. <CheckBox Content="{Binding Description}"
  215. IsChecked="{Binding IsSelected, Mode=TwoWay}"
  216. Tag="{RelativeSource FindAncestor, AncestorType={x:Type ComboBox}}"
  217. Click="Checkbox_OnClick"></CheckBox>
  218. </HierarchicalDataTemplate>
  219. </ComboBox.ItemTemplate>
  220. <ComboBox.Template>
  221. <ControlTemplate TargetType="ComboBox">
  222. <Grid>
  223. <ToggleButton Name="ToggleButton"
  224. Style="{StaticResource ComboBoxToggleButton}"
  225. Focusable="False"
  226. IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}">
  227. </ToggleButton>
  228. <ContentPresenter x:Name="Presenter"
  229. IsHitTestVisible="False"
  230. Margin="3, 3, 23, 3"
  231. VerticalAlignment="Center"
  232. HorizontalAlignment="Left">
  233. <ContentPresenter.Content>
  234. <TextBlock TextTrimming="CharacterEllipsis"
  235. Text="{Binding Path=Text, Mode=TwoWay, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}">
  236. </TextBlock>
  237. </ContentPresenter.Content>
  238. </ContentPresenter>
  239. <TextBox x:Name="EditableTextBox"
  240. Style="{x:Null}"
  241. Template="{StaticResource ComboBoxTextBox}"
  242. HorizontalAlignment="Left"
  243. VerticalAlignment="Center"
  244. Margin="3,3,23,3"
  245. Focusable="True"
  246. Background="Transparent"
  247. Visibility="Hidden"
  248. IsReadOnly="{TemplateBinding IsReadOnly}"/>
  249. <Popup
  250. Name="Popup"
  251. Placement="Bottom"
  252. IsOpen="{TemplateBinding IsDropDownOpen}"
  253. AllowsTransparency="True"
  254. Focusable="False"
  255. PopupAnimation="Slide">
  256. <Grid
  257. Name="DropDown"
  258. SnapsToDevicePixels="True"
  259. MinWidth="{TemplateBinding ActualWidth}"
  260. MaxHeight="{TemplateBinding MaxDropDownHeight}">
  261. <Border
  262. x:Name="DropDownBorder"
  263. Background="{StaticResource WindowBackgroundBrush}"
  264. BorderThickness="1"/>
  265. <ScrollViewer Margin="4,6,4,6" SnapsToDevicePixels="True" DataContext="{Binding}">
  266. <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" />
  267. </ScrollViewer>
  268. </Grid>
  269. </Popup>
  270. </Grid>
  271. <ControlTemplate.Triggers>
  272. <Trigger Property="HasItems" Value="false">
  273. <Setter TargetName="DropDownBorder" Property="MinHeight" Value="95"/>
  274. </Trigger>
  275. <Trigger Property="IsEnabled" Value="false">
  276. <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
  277. </Trigger>
  278. <Trigger Property="IsGrouping" Value="true">
  279. <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
  280. </Trigger>
  281. <Trigger SourceName="Popup" Property="Popup.AllowsTransparency" Value="true">
  282. <Setter TargetName="DropDownBorder" Property="CornerRadius" Value="4"/>
  283. <Setter TargetName="DropDownBorder" Property="Margin" Value="0,2,0,0"/>
  284. </Trigger>
  285. <Trigger Property="IsEditable" Value="true">
  286. <Setter Property="IsTabStop" Value="false"/>
  287. <Setter TargetName="EditableTextBox" Property="Visibility" Value="Visible"/>
  288. <Setter TargetName="Presenter" Property="Visibility" Value="Hidden"/>
  289. </Trigger>
  290. </ControlTemplate.Triggers>
  291. </ControlTemplate>
  292. </ComboBox.Template>
  293. </ComboBox>
  294. </Grid>
  295. </UserControl>