NativeCombox.xaml 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. <UserControl x:Class="CollaborativePlatformMain.Form.UserControlForm.NativeCombox"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  5. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  6. xmlns:local="clr-namespace:CollaborativePlatformMain.Form.UserControlForm"
  7. mc:Ignorable="d"
  8. d:DesignHeight="30" d:DesignWidth="200">
  9. <UserControl.Resources>
  10. <LinearGradientBrush x:Key="NormalBrush" StartPoint="0,0" EndPoint="0,1">
  11. <GradientBrush.GradientStops>
  12. <GradientStopCollection>
  13. <GradientStop Color="White" Offset="0.0"/>
  14. <GradientStop Color="White" 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="White" Offset="0.0"/>
  22. <GradientStop Color="White" 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="White" Offset="0.0"/>
  31. <GradientStop Color="White" 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="White" Offset="0.0"/>
  39. <GradientStop Color="White" Offset="0.1"/>
  40. <GradientStop Color="White" Offset="0.9"/>
  41. <GradientStop Color="White" Offset="1.0"/>
  42. </GradientStopCollection>
  43. </GradientBrush.GradientStops>
  44. </LinearGradientBrush>
  45. <SolidColorBrush x:Key="DisabledForegroundBrush" Color="White" />
  46. <SolidColorBrush x:Key="DisabledBackgroundBrush" Color="White" />
  47. <SolidColorBrush x:Key="WindowBackgroundBrush" Color="White" />
  48. <SolidColorBrush x:Key="SelectedBackgroundBrush" Color="White" />
  49. <SolidColorBrush x:Key="ComboBox.Static.Border" Color="White"/>
  50. <SolidColorBrush x:Key="ComboBox.Static.Editable.Background" Color="White"/>
  51. <SolidColorBrush x:Key="ComboBox.Static.Editable.Border" Color="White"/>
  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="White"/>
  55. <LinearGradientBrush x:Key="ComboBox.MouseOver.Background" EndPoint="0,1" StartPoint="0,0">
  56. <GradientStop Color="White" Offset="0.0"/>
  57. <GradientStop Color="White" Offset="1.0"/>
  58. </LinearGradientBrush>
  59. <SolidColorBrush x:Key="ComboBox.MouseOver.Border" Color="#FF7EB4EA"/>
  60. <SolidColorBrush x:Key="ComboBox.MouseOver.Editable.Background" Color="White"/>
  61. <SolidColorBrush x:Key="ComboBox.MouseOver.Editable.Border" Color="White"/>
  62. <LinearGradientBrush x:Key="ComboBox.MouseOver.Editable.Button.Background" EndPoint="0,1" StartPoint="0,0">
  63. <GradientStop Color="White" Offset="0.0"/>
  64. <GradientStop Color="White" Offset="1.0"/>
  65. </LinearGradientBrush>
  66. <SolidColorBrush x:Key="ComboBox.MouseOver.Editable.Button.Border" Color="White"/>
  67. <SolidColorBrush x:Key="ComboBox.Pressed.Glyph" Color="White"/>
  68. <LinearGradientBrush x:Key="ComboBox.Pressed.Background" EndPoint="0,1" StartPoint="0,0">
  69. <GradientStop Color="White" Offset="0.0"/>
  70. <GradientStop Color="White" Offset="1.0"/>
  71. </LinearGradientBrush>
  72. <SolidColorBrush x:Key="ComboBox.Pressed.Border" Color="White"/>
  73. <SolidColorBrush x:Key="ComboBox.Pressed.Editable.Background" Color="White"/>
  74. <SolidColorBrush x:Key="ComboBox.Pressed.Editable.Border" Color="White"/>
  75. <LinearGradientBrush x:Key="ComboBox.Pressed.Editable.Button.Background" EndPoint="0,1" StartPoint="0,0">
  76. <GradientStop Color="White" Offset="0.0"/>
  77. <GradientStop Color="White" Offset="1.0"/>
  78. </LinearGradientBrush>
  79. <SolidColorBrush x:Key="ComboBox.Pressed.Editable.Button.Border" Color="White"/>
  80. <SolidColorBrush x:Key="ComboBox.Disabled.Glyph" Color="White"/>
  81. <SolidColorBrush x:Key="ComboBox.Disabled.Background" Color="White"/>
  82. <SolidColorBrush x:Key="ComboBox.Disabled.Border" Color="White"/>
  83. <SolidColorBrush x:Key="ComboBox.Disabled.Editable.Background" Color="White"/>
  84. <SolidColorBrush x:Key="ComboBox.Disabled.Editable.Border" Color="White"/>
  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="Black"/>
  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" SnapsToDevicePixels="true" Background="White">
  100. <Border x:Name="splitBorder" HorizontalAlignment="Right" Margin="0,0,2,0" SnapsToDevicePixels="true" Width="25" BorderBrush="White" BorderThickness="1,0,0,0">
  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="Background" TargetName="splitBorder" Value="{StaticResource ComboBox.Static.Editable.Button.Background}"/>
  114. </MultiDataTrigger>
  115. <Trigger Property="IsMouseOver" Value="true">
  116. <Setter Property="Fill" TargetName="arrow" Value="{StaticResource ComboBox.MouseOver.Glyph}"/>
  117. </Trigger>
  118. <MultiDataTrigger>
  119. <MultiDataTrigger.Conditions>
  120. <Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="true"/>
  121. <Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="false"/>
  122. </MultiDataTrigger.Conditions>
  123. <Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.MouseOver.Background}"/>
  124. </MultiDataTrigger>
  125. <MultiDataTrigger>
  126. <MultiDataTrigger.Conditions>
  127. <Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="true"/>
  128. <Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="true"/>
  129. </MultiDataTrigger.Conditions>
  130. <Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.MouseOver.Editable.Background}"/>
  131. <Setter Property="Background" TargetName="splitBorder" Value="{StaticResource ComboBox.MouseOver.Editable.Button.Background}"/>
  132. </MultiDataTrigger>
  133. <Trigger Property="IsPressed" Value="true">
  134. <Setter Property="Fill" TargetName="arrow" Value="{StaticResource ComboBox.Pressed.Glyph}"/>
  135. </Trigger>
  136. <MultiDataTrigger>
  137. <MultiDataTrigger.Conditions>
  138. <Condition Binding="{Binding IsPressed, RelativeSource={RelativeSource Self}}" Value="true"/>
  139. <Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="false"/>
  140. </MultiDataTrigger.Conditions>
  141. <Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.Pressed.Background}"/>
  142. </MultiDataTrigger>
  143. <MultiDataTrigger>
  144. <MultiDataTrigger.Conditions>
  145. <Condition Binding="{Binding IsPressed, RelativeSource={RelativeSource Self}}" Value="true"/>
  146. <Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="true"/>
  147. </MultiDataTrigger.Conditions>
  148. <Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.Pressed.Editable.Background}"/>
  149. <Setter Property="Background" TargetName="splitBorder" Value="{StaticResource ComboBox.Pressed.Editable.Button.Background}"/>
  150. </MultiDataTrigger>
  151. <Trigger Property="IsEnabled" Value="false">
  152. <Setter Property="Fill" TargetName="arrow" Value="{StaticResource ComboBox.Disabled.Glyph}"/>
  153. </Trigger>
  154. <MultiDataTrigger>
  155. <MultiDataTrigger.Conditions>
  156. <Condition Binding="{Binding IsEnabled, RelativeSource={RelativeSource Self}}" Value="false"/>
  157. <Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="false"/>
  158. </MultiDataTrigger.Conditions>
  159. <Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.Disabled.Background}"/>
  160. </MultiDataTrigger>
  161. <MultiDataTrigger>
  162. <MultiDataTrigger.Conditions>
  163. <Condition Binding="{Binding IsEnabled, RelativeSource={RelativeSource Self}}" Value="false"/>
  164. <Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="true"/>
  165. </MultiDataTrigger.Conditions>
  166. <Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.Disabled.Editable.Background}"/>
  167. <Setter Property="Background" TargetName="splitBorder" Value="{StaticResource ComboBox.Disabled.Editable.Button.Background}"/>
  168. </MultiDataTrigger>
  169. </ControlTemplate.Triggers>
  170. </ControlTemplate>
  171. </Setter.Value>
  172. </Setter>
  173. </Style>
  174. <Style x:Key="{x:Type ComboBoxItem}" TargetType="ComboBoxItem">
  175. <Setter Property="SnapsToDevicePixels" Value="true"/>
  176. <Setter Property="OverridesDefaultStyle" Value="true"/>
  177. <Setter Property="Template">
  178. <Setter.Value>
  179. <ControlTemplate TargetType="ComboBoxItem">
  180. <Border
  181. Name="Border"
  182. Padding="2"
  183. SnapsToDevicePixels="true">
  184. <ContentPresenter />
  185. </Border>
  186. <ControlTemplate.Triggers>
  187. <Trigger Property="IsHighlighted" Value="true">
  188. <Setter TargetName="Border" Property="Background" Value="{StaticResource SelectedBackgroundBrush}"/>
  189. </Trigger>
  190. <Trigger Property="IsEnabled" Value="false">
  191. <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
  192. </Trigger>
  193. </ControlTemplate.Triggers>
  194. </ControlTemplate>
  195. </Setter.Value>
  196. </Setter>
  197. </Style>
  198. </UserControl.Resources>
  199. <Grid Background="#aaa">
  200. <Border Margin="1,1,1,1" BorderBrush="Black" CornerRadius="4,4,4,4">
  201. <ComboBox x:Name="CheckableCombo">
  202. <ComboBox.ItemTemplate>
  203. <HierarchicalDataTemplate>
  204. <CheckBox Content="{Binding Name}" Height="30"
  205. IsChecked="{Binding IsSelect, Mode=TwoWay}"
  206. Tag="{RelativeSource FindAncestor, AncestorType={x:Type ComboBox}}"
  207. Click="CheckBox_Click" VerticalContentAlignment="Center" HorizontalAlignment="Left"></CheckBox>
  208. </HierarchicalDataTemplate>
  209. </ComboBox.ItemTemplate>
  210. <ComboBox.Template>
  211. <ControlTemplate TargetType="ComboBox">
  212. <Grid>
  213. <ToggleButton Name="ToggleButton"
  214. Style="{StaticResource ComboBoxToggleButton}"
  215. Focusable="False" Click="ToggleButton_Click"
  216. IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}">
  217. </ToggleButton>
  218. <ContentPresenter x:Name="Presenter"
  219. IsHitTestVisible="False"
  220. Margin="3, 3, 23, 3"
  221. VerticalAlignment="Center"
  222. HorizontalAlignment="Left">
  223. <ContentPresenter.Content>
  224. <TextBlock TextTrimming="CharacterEllipsis"
  225. Text="{Binding Path=Text, Mode=TwoWay, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}">
  226. </TextBlock>
  227. </ContentPresenter.Content>
  228. </ContentPresenter>
  229. <TextBox x:Name="EditableTextBox"
  230. Style="{x:Null}"
  231. Template="{StaticResource ComboBoxTextBox}"
  232. HorizontalAlignment="Left"
  233. VerticalAlignment="Center"
  234. Margin="3,3,23,3"
  235. Focusable="True"
  236. Background="Transparent"
  237. Visibility="Hidden"
  238. IsReadOnly="{TemplateBinding IsReadOnly}"/>
  239. <Popup
  240. Name="Popup"
  241. Placement="Bottom"
  242. IsOpen="{TemplateBinding IsDropDownOpen}"
  243. AllowsTransparency="True"
  244. Focusable="False"
  245. PopupAnimation="Slide">
  246. <Grid
  247. Name="DropDown"
  248. SnapsToDevicePixels="True"
  249. MinWidth="{TemplateBinding ActualWidth}"
  250. MaxHeight="{TemplateBinding MaxDropDownHeight}">
  251. <Border
  252. x:Name="DropDownBorder"
  253. Background="{StaticResource WindowBackgroundBrush}" BorderThickness="1,1,1,1" BorderBrush="White"/>
  254. <ScrollViewer Margin="4,6,4,6" SnapsToDevicePixels="True" DataContext="{Binding}">
  255. <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" />
  256. </ScrollViewer>
  257. </Grid>
  258. </Popup>
  259. </Grid>
  260. <ControlTemplate.Triggers>
  261. <Trigger Property="HasItems" Value="false">
  262. <Setter TargetName="DropDownBorder" Property="MinHeight" Value="95"/>
  263. </Trigger>
  264. <Trigger Property="IsEnabled" Value="false">
  265. <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
  266. </Trigger>
  267. <Trigger Property="IsGrouping" Value="true">
  268. <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
  269. </Trigger>
  270. <Trigger SourceName="Popup" Property="Popup.AllowsTransparency" Value="true">
  271. <Setter TargetName="DropDownBorder" Property="CornerRadius" Value="4"/>
  272. <Setter TargetName="DropDownBorder" Property="Margin" Value="0,2,0,0"/>
  273. </Trigger>
  274. <Trigger Property="IsEditable" Value="true">
  275. <Setter Property="IsTabStop" Value="false"/>
  276. <Setter TargetName="EditableTextBox" Property="Visibility" Value="Visible"/>
  277. <Setter TargetName="Presenter" Property="Visibility" Value="Hidden"/>
  278. </Trigger>
  279. </ControlTemplate.Triggers>
  280. </ControlTemplate>
  281. </ComboBox.Template>
  282. </ComboBox>
  283. </Border>
  284. </Grid>
  285. </UserControl>