|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
- <!-- ComBoBox项鼠标经过背景色 -->
- <SolidColorBrush x:Key="ComboBoxMouseOverBackground" Color="#f0f0f0" />
- <!-- Combox右侧下拉按钮 -->
- <Style x:Key="ComboxStyleBtn" TargetType="ToggleButton">
- <Setter Property="Template">
- <Setter.Value>
- <ControlTemplate>
- <!-- 下拉按钮内部背景色 -->
- <Border
- x:Name="Back"
- Background="Transparent"
- BorderBrush="Transparent"
- BorderThickness="1">
- <!-- 下拉按钮内边框 -->
- <Label
- Name="PathFill"
- Height="30"
- HorizontalAlignment="Right"
- VerticalAlignment="Center"
- VerticalContentAlignment="Center"
- Content="ˇ"
- FontSize="30" />
- </Border>
- <ControlTemplate.Triggers>
- <Trigger Property="IsMouseOver" Value="True">
- <Setter TargetName="Back" Property="Background" Value="Transparent" />
- <Setter TargetName="Back" Property="BorderBrush" Value="Transparent" />
- </Trigger>
- </ControlTemplate.Triggers>
- </ControlTemplate>
- </Setter.Value>
- </Setter>
- </Style>
- <!-- Combox -->
- <Style x:Key="ComboBoxStyle" TargetType="ComboBox">
- <Setter Property="ItemContainerStyle">
- <Setter.Value>
- <!-- ComBoxItem -->
- <Style TargetType="{x:Type ComboBoxItem}">
- <Setter Property="MinHeight" Value="32" />
- <Setter Property="MinWidth" Value="60" />
- <Setter Property="Template">
- <Setter.Value>
- <ControlTemplate TargetType="{x:Type ComboBoxItem}">
- <Border
- Name="_back"
- Background="Transparent"
- BorderBrush="#f3f3f3"
- BorderThickness="0,0,0,0">
- <ContentPresenter Margin="10,0,10,0" VerticalAlignment="Center" />
- </Border>
- <ControlTemplate.Triggers>
- <Trigger Property="IsMouseOver" Value="True">
- <Setter TargetName="_back" Property="Background" Value="{StaticResource ComboBoxMouseOverBackground}" />
- </Trigger>
- <!-- 下拉框背景色 -->
- <Trigger Property="IsHighlighted" Value="True">
- <Setter TargetName="_back" Property="Background" Value="{StaticResource ComboBoxMouseOverBackground}" />
- </Trigger>
- </ControlTemplate.Triggers>
- </ControlTemplate>
- </Setter.Value>
- </Setter>
- </Style>
- </Setter.Value>
- </Setter>
- <Setter Property="Template">
- <Setter.Value>
- <ControlTemplate TargetType="ComboBox">
- <Grid>
- <!-- 文字区域背景和边线样式 -->
- <TextBox
- Grid.Column="0"
- Padding="10,0,0,0"
- VerticalAlignment="Center"
- Background="Transparent"
- BorderBrush="#c0c0c0"
- BorderThickness="0"
- Foreground="Black"
- IsReadOnly="{TemplateBinding IsReadOnly}"
- Text="{TemplateBinding Text}" />
- <Border
- Grid.Column="0"
- BorderBrush="#c0c0c0"
- BorderThickness="0.6"
- CornerRadius="1,0,0,1" />
- <!-- 右侧下拉button设置 -->
- <Border BorderThickness="0">
- <ToggleButton
- BorderBrush="Black"
- BorderThickness="3"
- ClickMode="Press"
- IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
- Style="{StaticResource ComboxStyleBtn}" />
- </Border>
- <!-- 弹出popup整体设置 -->
- <Popup
- x:Name="Popup"
- AllowsTransparency="True"
- Focusable="False"
- IsOpen="{TemplateBinding IsDropDownOpen}"
- Placement="Bottom"
- PopupAnimation="Slide">
- <Grid
- x:Name="DropDown"
- Width="{TemplateBinding ActualWidth}"
- MaxHeight="200"
- SnapsToDevicePixels="True">
- <Border
- x:Name="DropDownBorder"
- BorderBrush="#e8e8e8"
- BorderThickness="1,0,1,1" />
- <ScrollViewer
- Margin="1"
- CanContentScroll="True"
- HorizontalScrollBarVisibility="Disabled"
- SnapsToDevicePixels="True"
- VerticalScrollBarVisibility="Auto">
- <!-- StackPanel 用于显示子级,方法是将 IsItemsHost 设置为 True -->
- <StackPanel
- Background="White"
- IsItemsHost="True"
- KeyboardNavigation.DirectionalNavigation="Contained" />
- </ScrollViewer>
- </Grid>
- </Popup>
- </Grid>
- </ControlTemplate>
- </Setter.Value>
- </Setter>
- </Style>
- </ResourceDictionary>
|