在Wpf中单击鼠标左键时,为Combobox项目设置背景颜色 [英] Set Background color for Combobox Items when mouse left button clicked in Wpf

查看:113
本文介绍了在Wpf中单击鼠标左键时,为Combobox项目设置背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

单击鼠标左键时,为Combobox项目设置背景颜色 

Set Background color for Combobox Items when mouse left button clicked 

推荐答案

您好,

我是不确定你的问题,你想在鼠标悬停时改变组合框背景颜色吗?如果是,您可以查看以下代码:

I am not sure your problem, do you want to change comboboxitem background color when mouseover? If yes, you can take a look the following code:

 <ComboBox
            Width="300"
            Height="30"
            Margin="5"
            ItemsSource="{Binding}">
<ComboBox.ItemContainerStyle>
                <Style TargetType="{x:Type ComboBoxItem}">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate>
                                <Border x:Name="border">
                                    <Grid>

                                        <ContentPresenter
                                            Content="{Binding}"
                                            ContentTemplate="{StaticResource comboboxitem}"
                                            SnapsToDevicePixels="True" />
                                    </Grid>
                                </Border>
                                <ControlTemplate.Triggers>
                                    <Trigger Property="IsMouseOver" Value="true">
                                        <Setter TargetName="border" Property="Background" Value="Red" />
                                        <!--<Setter TargetName="border" Property="BorderBrush" Value="Red" />
                                        <Setter TargetName="border" Property="BorderThickness" Value="2" />-->
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </ComboBox.ItemContainerStyle>
</ComboBox>

或者你想改变组合框背景?

Or you want to change combobox background?

最好的问候,

Cherry


这篇关于在Wpf中单击鼠标左键时,为Combobox项目设置背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆