WPF Combobox项目风格

时间:2017-05-23 22:31:46

标签: wpf wpf-style

有人可以指导我如何设置有复选框作为组合框的组合框。我试图找到重复无效,所以如果这是一个重复的问题,请告诉我正确的问题。当前发生的行为是当鼠标悬停在某个项目上时,它会使背景和前景变黑。我喜欢的是背景可能是灰色或前景是白色的白色鼠标悬停在上面。我不能为我的生活找到合适的风格颜色画笔来实现这一点......任何帮助都会很棒!

这是xaml:

<ComboBox ItemsSource="{Binding PromptFilterList}">
<ComboBox.ItemTemplate>
    <DataTemplate>
        <CheckBox IsChecked="{Binding IsSelected}" Content="{Binding Item.Description}"/>
    </DataTemplate>
</ComboBox.ItemTemplate>

这里发生了什么,因为你可以看到当鼠标悬停在项目上时字母不清晰:

enter image description here

2 个答案:

答案 0 :(得分:0)

我希望这可以帮到你。

<ControlTemplate TargetType="{x:Type ComboBoxItem}">
<ControlTemplate.Triggers>
     <Trigger Property="IsHighlighted" Value="true">
     <Setter Property="Opacity" TargetName="Border" Value="1" />
     <Setter Property="Background" TargetName="Border" Value="{your requirement}" />
     <Setter Property="BorderBrush" TargetName="Border" Value="{your requirement}" />
     <Setter Property="Foreground" Value="{your requirement}" />                            
     </Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>

答案 1 :(得分:0)

这是我在评论中提到的高亮颜色资源。在WPF中,高亮等系统颜色是具有预定义静态键的画笔资源。在给定范围内,您可以使用该键定义新资源,它将覆盖默认值。

quite a long list of those resource keys

Administrator@WIN-XXXXXXXXXXX c:\Administrator\OpenServer\OpenServer\domains\mysite.us
$ php yii two
An Error occurred while handling another error:
exception 'ReflectionException' with message 'Class yii\console\components\TwoController does not exist' in C:\Administrator\OpenServer\OpenServer\domains\mysite.us\vendor\yiisoft\yii2\di\Container.php:424
Stack trace:
#0 C:\Administrator\OpenServer\OpenServer\domains\mysite.us\vendor\yiisoft\yii2\di\Container.php(424): ReflectionClass->__construct('yii\\console\\com...')
#1 C:\Administrator\OpenServer\OpenServer\domains\mysite.us\vendor\yiisoft\yii2\di\Container.php(364): yii\di\Container->getDependencies('yii\\console\\com...')
#2 C:\Administrator\OpenServer\OpenServer\domains\mysite.us\vendor\yiisoft\yii2\di\Container.php(156): yii\di\Container->build('yii\\console\\com...', Array, Array)
#3 C:\Administrator\OpenServer\OpenServer\domains\mysite.us\vendor\yiisoft\yii2\BaseYii.php(344): yii\di\Container->get('yii\\console\\com...', Array, Array)
#4 C:\Administrator\OpenServer\OpenServer\domains\mysite.us\vendor\yiisoft\yii2\base\Module.php(578): yii\BaseYii::createObject(Array, Array)
#5 C:\Administrator\OpenServer\OpenServer\domains\mysite.us\vendor\yiisoft\yii2\console\UnknownCommandException.php(79): yii\base\Module->createController('test')
#6 C:\Administrator\OpenServer\OpenServer\domains\mysite.us\vendor\yiisoft\yii2\console\ErrorHandler.php(35): yii\console\UnknownCommandException->getSuggestedAlternatives()
#7 C:\Administrator\OpenServer\OpenServer\domains\mysite.us\vendor\yiisoft\yii2\base\ErrorHandler.php(111): yii\console\ErrorHandler->renderException(Object(yii\console\UnknownCommandException))
#8 [internal function]: yii\base\ErrorHandler->handleException(Object(yii\console\UnknownCommandException))
#9 {main}
Previous exception:
exception 'yii\base\InvalidRouteException' with message 'Unable to resolve the request "two".' in C:\Administrator\OpenServer\OpenServer\domains\mysite.us\vendor\yiisoft\yii2\base\Module.php:532
Stack trace:
#0 C:\Administrator\OpenServer\OpenServer\domains\mysite.us\vendor\yiisoft\yii2\console\Application.php(180): yii\base\Module->runAction('two', Array)
#1 C:\Administrator\OpenServer\OpenServer\domains\mysite.us\vendor\yiisoft\yii2\console\Application.php(147): yii\console\Application->runAction('two', Array)
#2 C:\Administrator\OpenServer\OpenServer\domains\mysite.us\vendor\yiisoft\yii2\base\Application.php(380): yii\console\Application->handleRequest(Object(yii\console\Request))
#3 C:\Administrator\OpenServer\OpenServer\domains\mysite.us\yii(27): yii\base\Application->run()
#4 {main}

Next exception 'yii\console\UnknownCommandException' with message 'Unknown command "two".' in C:\Administrator\OpenServer\OpenServer\domains\mysite.us\vendor\yiisoft\yii2\console\Application.php:183
Stack trace:
#0 C:\Administrator\OpenServer\OpenServer\domains\mysite.us\vendor\yiisoft\yii2\console\Application.php(147): yii\console\Application->runAction('two', Array)
#1 C:\Administrator\OpenServer\OpenServer\domains\mysite.us\vendor\yiisoft\yii2\base\Application.php(380): yii\console\Application->handleRequest(Object(yii\console\Request))
#2 C:\Administrator\OpenServer\OpenServer\domains\mysite.us\yii(27): yii\base\Application->run()
#3 {main}