给一个Togglebutton这个颜色“#FF5D0000”在MainWindow [英] Give a Togglebutton this Color "#FF5D0000" in the MainWindow
问题描述
推荐答案
Sealed类Brushes包含预定义的SolidColorBrush对象你可以选择。但是没有一个名为Owncolor的对象。 Owncolor是您创建的变量,已使用您的自定义SolidColorBrush"#FF5D0000"进行初始化。您只需将
分配给按钮的Foreground属性,如下所示:
The Sealed class Brushes contains pre-defined SolidColorBrush objects you can choose from. But there is not an object named Owncolor. Owncolor is a variable you created that is already initialized with your custom SolidColorBrush "#FF5D0000". You simply assign it to the Foreground property of your button as follows:
SolidColorBrush Owncolor = (SolidColorBrush)(new BrushConverter().ConvertFrom("#FF5D0000"));
ToggleButton.Foreground = Owncolor;
或更简洁
ToggleButton.Foreground = (SolidColorBrush)(new BrushConverter().ConvertFrom("#FF5D0000"));
其中'ToggleButton'有希望是你的ToggleButton的XAML名称?!选择与类名不同的名称可能更好,例如。 'toggleButton'。
where 'ToggleButton' hopefully is the XAML name of your ToggleButton?! It might be better to choose a name different from the class name, eg. 'toggleButton'.
wizend
这篇关于给一个Togglebutton这个颜色“#FF5D0000”在MainWindow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!