Combox的样式

来张图片

<Window.Resources>
        <Style x:Key="ComboBoxItemStyle3" TargetType="{x:Type ComboBoxItem}">
            <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
            <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
            <Setter Property="Padding" Value="3,0,3,0"/>
            <Setter Property="Background" Value="#FF085B68"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ComboBoxItem}">
                        <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
                            <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsHighlighted" Value="true">
                                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
                                <Setter Property="Background" TargetName="Bd" Value="#FF23A4A4"/>
                            </Trigger>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="BorderBrush" Value="#FF368380"/>
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="BorderBrush" Value="#FF5AC5C0"/>
                    <Setter Property="Background" Value="#FF16BBD4"/>
                    <Setter Property="Foreground" Value="#FFDA2828"/>
                </Trigger>
            </Style.Triggers>
        </Style>
        <Style x:Key="ComboBoxStyle2" TargetType="{x:Type ComboBox}">
            <Setter Property="SnapsToDevicePixels" Value="true"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ComboBox}">
                        <Grid>
                            <!-- The ToggleButton is databound to the ComboBox itself to toggle IsDropDownOpen -->
                            <ToggleButton Grid.Column="2" Template="{DynamicResource ComboBoxToggleButton}" x:Name="ToggleButton" Focusable="false" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" ClickMode="Press" Background="#FFB5EEEB"/>
                            <ContentPresenter HorizontalAlignment="Left" Margin="3,3,23,3" x:Name="ContentSite" VerticalAlignment="Center" Content="{TemplateBinding SelectionBoxItem}" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" IsHitTestVisible="False"/>

                            <!-- The TextBox must be named PART_EditableTextBox or ComboBox will not recognize it -->
                            <TextBox Visibility="Hidden" Template="{DynamicResource ComboBoxTextBox}" HorizontalAlignment="Left" Margin="3,3,23,3" x:Name="PART_EditableTextBox" Style="{x:Null}" VerticalAlignment="Center" Focusable="True" Background="Transparent" IsReadOnly="{TemplateBinding IsReadOnly}" d:IsHidden="True"/>

                            <!-- The Popup shows the list of items in the ComboBox. IsOpen is databound to IsDropDownOpen which is toggled via the ComboBoxToggleButton -->
                            <Popup IsOpen="{TemplateBinding IsDropDownOpen}" Placement="Bottom" x:Name="Popup" Focusable="False" AllowsTransparency="True" PopupAnimation="Slide" d:IsHidden="True">
                                <Grid MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{TemplateBinding ActualWidth}" x:Name="DropDown" SnapsToDevicePixels="True">
                                    <Border x:Name="DropDownBorder" Background="#FF0B6F85" BorderBrush="#FF18AA7B" BorderThickness="0.3" CornerRadius="5"/>
                                    <ScrollViewer x:Name="scrollViewer" Margin="4,4,4,4.667" Style="{DynamicResource SimpleScrollViewer}" SnapsToDevicePixels="True" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" CanContentScroll="True" Background="#FF1494B0">

                                        <!-- The StackPanel is used to display the children by setting IsItemsHost to be True -->
                                        <StackPanel x:Name="stackPanel" IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" Background="#FF0B6F85"/>

                                    </ScrollViewer>
                                </Grid>
                            </Popup>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <!-- This forces the DropDown to have a minimum size if it is empty -->
                            <Trigger Property="AllowsTransparency" SourceName="Popup" Value="true">
                                <Setter Property="CornerRadius" Value="4" TargetName="DropDownBorder"/>
                                <Setter Property="Margin" Value="0,2,0,0" TargetName="DropDownBorder"/>
                            </Trigger>
                            <Trigger Property="IsEditable" Value="true">
                                <Setter Property="IsTabStop" Value="false"/>
                                <Setter Property="Visibility" Value="Visible" TargetName="PART_EditableTextBox"/>
                                <Setter Property="Visibility" Value="Hidden" TargetName="ContentSite"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="Background">
                <Setter.Value>
                    <SolidColorBrush Color="#FF3A8591" Opacity="0.8"/>
                </Setter.Value>
            </Setter>
            <Setter Property="BorderBrush" Value="#FF370F8D"/>
            <Setter Property="Foreground" Value="#FF39F174"/>
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Foreground" Value="#FF14933C"/>
                    <Setter Property="Background" Value="{x:Null}"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>
  

<!-- 调用时的 -->
    <Grid>
        <ComboBox x:Name="comboBox" Height="25" Margin="27,75,0,0" Style="{DynamicResource ComboBoxStyle2}" VerticalAlignment="Top" ItemContainerStyle="{DynamicResource ComboBoxItemStyle3}" HorizontalAlignment="Left" Width="163" MaxDropDownHeight="200">
           
        </ComboBox>
    </Grid>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值