星火微课系统客户端
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

StyleComboBox.xaml 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  2. <!-- ComBoBox项鼠标经过背景色 -->
  3. <SolidColorBrush x:Key="ComboBoxMouseOverBackground" Color="#f0f0f0" />
  4. <!-- Combox右侧下拉按钮 -->
  5. <Style x:Key="ComboxStyleBtn" TargetType="ToggleButton">
  6. <Setter Property="Template">
  7. <Setter.Value>
  8. <ControlTemplate>
  9. <!-- 下拉按钮内部背景色 -->
  10. <Border
  11. x:Name="Back"
  12. Background="Transparent"
  13. BorderBrush="Transparent"
  14. BorderThickness="1">
  15. <!-- 下拉按钮内边框 -->
  16. <Label
  17. Name="PathFill"
  18. Height="30"
  19. HorizontalAlignment="Right"
  20. VerticalAlignment="Center"
  21. VerticalContentAlignment="Center"
  22. Content="ˇ"
  23. FontSize="30" />
  24. </Border>
  25. <ControlTemplate.Triggers>
  26. <Trigger Property="IsMouseOver" Value="True">
  27. <Setter TargetName="Back" Property="Background" Value="Transparent" />
  28. <Setter TargetName="Back" Property="BorderBrush" Value="Transparent" />
  29. </Trigger>
  30. </ControlTemplate.Triggers>
  31. </ControlTemplate>
  32. </Setter.Value>
  33. </Setter>
  34. </Style>
  35. <!-- Combox -->
  36. <Style x:Key="ComboBoxStyle" TargetType="ComboBox">
  37. <Setter Property="ItemContainerStyle">
  38. <Setter.Value>
  39. <!-- ComBoxItem -->
  40. <Style TargetType="{x:Type ComboBoxItem}">
  41. <Setter Property="MinHeight" Value="32" />
  42. <Setter Property="MinWidth" Value="60" />
  43. <Setter Property="Template">
  44. <Setter.Value>
  45. <ControlTemplate TargetType="{x:Type ComboBoxItem}">
  46. <Border
  47. Name="_back"
  48. Background="Transparent"
  49. BorderBrush="#f3f3f3"
  50. BorderThickness="0,0,0,0">
  51. <ContentPresenter Margin="10,0,10,0" VerticalAlignment="Center" />
  52. </Border>
  53. <ControlTemplate.Triggers>
  54. <Trigger Property="IsMouseOver" Value="True">
  55. <Setter TargetName="_back" Property="Background" Value="{StaticResource ComboBoxMouseOverBackground}" />
  56. </Trigger>
  57. <!-- 下拉框背景色 -->
  58. <Trigger Property="IsHighlighted" Value="True">
  59. <Setter TargetName="_back" Property="Background" Value="{StaticResource ComboBoxMouseOverBackground}" />
  60. </Trigger>
  61. </ControlTemplate.Triggers>
  62. </ControlTemplate>
  63. </Setter.Value>
  64. </Setter>
  65. </Style>
  66. </Setter.Value>
  67. </Setter>
  68. <Setter Property="Template">
  69. <Setter.Value>
  70. <ControlTemplate TargetType="ComboBox">
  71. <Grid>
  72. <!-- 文字区域背景和边线样式 -->
  73. <TextBox
  74. Grid.Column="0"
  75. Padding="10,0,0,0"
  76. VerticalAlignment="Center"
  77. Background="Transparent"
  78. BorderBrush="#c0c0c0"
  79. BorderThickness="0"
  80. Foreground="Black"
  81. IsReadOnly="{TemplateBinding IsReadOnly}"
  82. Text="{TemplateBinding Text}" />
  83. <Border
  84. Grid.Column="0"
  85. BorderBrush="#c0c0c0"
  86. BorderThickness="0.6"
  87. CornerRadius="1,0,0,1" />
  88. <!-- 右侧下拉button设置 -->
  89. <Border BorderThickness="0">
  90. <ToggleButton
  91. BorderBrush="Black"
  92. BorderThickness="3"
  93. ClickMode="Press"
  94. IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
  95. Style="{StaticResource ComboxStyleBtn}" />
  96. </Border>
  97. <!-- 弹出popup整体设置 -->
  98. <Popup
  99. x:Name="Popup"
  100. AllowsTransparency="True"
  101. Focusable="False"
  102. IsOpen="{TemplateBinding IsDropDownOpen}"
  103. Placement="Bottom"
  104. PopupAnimation="Slide">
  105. <Grid
  106. x:Name="DropDown"
  107. Width="{TemplateBinding ActualWidth}"
  108. MaxHeight="200"
  109. SnapsToDevicePixels="True">
  110. <Border
  111. x:Name="DropDownBorder"
  112. BorderBrush="#e8e8e8"
  113. BorderThickness="1,0,1,1" />
  114. <ScrollViewer
  115. Margin="1"
  116. CanContentScroll="True"
  117. HorizontalScrollBarVisibility="Disabled"
  118. SnapsToDevicePixels="True"
  119. VerticalScrollBarVisibility="Auto">
  120. <!-- StackPanel 用于显示子级,方法是将 IsItemsHost 设置为 True -->
  121. <StackPanel
  122. Background="White"
  123. IsItemsHost="True"
  124. KeyboardNavigation.DirectionalNavigation="Contained" />
  125. </ScrollViewer>
  126. </Grid>
  127. </Popup>
  128. </Grid>
  129. </ControlTemplate>
  130. </Setter.Value>
  131. </Setter>
  132. </Style>
  133. </ResourceDictionary>