更改复选框控件中“勾号”的颜色 [英] Changing the color of the 'Tick' in the Checkbox Control

查看:117
本文介绍了更改复选框控件中“勾号”的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想改变Checkbox Control中滴答的颜色,但似乎没有一种简单的方法可以做到这一点。它似乎不尊重BorderBrush或Foreground;并且似乎没有Checbox.TickColor属性。

I'm looking to change the color of the tick in a Checkbox Control, but there doesn't seem to be a simple way to do this. It doesn't seem to respect BorderBrush or Foreground; and there doesn't seem to be a Checbox.TickColor property either.

我发现很多人试图这样做,我能够成功地改变滴答的颜色提供大约150行Xaml的Style。这似乎非常沉重,每次我想改变刻度的颜色。

I've found many people attempting to do this, and I was able to successfully change the color of the tick by supplying a Style that was roughly 150 lines of Xaml. This seems extremely heavy handed every time I want to change the color of a tick.

当其他每个控件看起来简单/直观时,是否有人知道为什么这是Checkbox的情况。嘀嗒是疏忽还是我错过了什么?

Does anyone have information on why this is the case for Checkbox when every other control seems simple/intuitive. Was the tick an oversight or am I missing something?

感谢您提供有关此问题的任何信息,欢呼,以及
Coltin

Thanks for any information regarding this issue, cheers,
Coltin

推荐答案

您需要做的是编辑ControlTemplate(分配给  Template属性)。在ControlTemplate中,您可以使用所需的任何内容定义控件的外观。在CheckBox的默认ControlTemplate中,使用名为CheckMark的Path定义了
,因此您只需更改Path的Fill属性,它就应该更改Tick的颜色。因为这是一个ControlTemplate,你可以将它放在参考资料中,并将它用于你希望
改变其刻度颜色的任何其他CheckBox。如果您之前从未使用过ControlTemplates,那么您可能需要了解一些有助于理解这一点的内容。祝你好运!

What you need to do is edit the ControlTemplate (which is assigned to the Template property). In a ControlTemplate, you can define what a Control looks like using anything you want. In the default ControlTemplate for the CheckBox, the tick is defined using a Path with the name CheckMark, so you could just change the Fill property of the Path, and it should change the color of the Tick. Because this is a ControlTemplate, you can put it in the Resources and use it for any of the other CheckBoxes you want to change the tick color of. If you have never used ControlTemplates before, you may want to learn a little about that to help you understand this. Good Luck!


这篇关于更改复选框控件中“勾号”的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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