wpf 在 MahApp 应用程序中设置图标颜色

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20721723/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 10:16:51  来源:igfitidea点击:

Set the icon color in a MahApp application

wpfmahapps.metro

提问by Raúl Ota?o

I want to set the icon color in a MahApp application, but the brush is not working. In this example the icoun should be white, but still it is black.

我想在 MahApp 应用程序中设置图标颜色,但画笔不起作用。在这个例子中,图标应该是白色的,但它仍然是黑色的。

<Rectangle Width="20" Height="20">
    <Rectangle.Resources>
       <SolidColorBrush x:Key="BlackBrush" Color="White" />
    </Rectangle.Resources>
    <Rectangle.Fill>
        <VisualBrush Stretch="Fill" Visual="{StaticResource appbar_cupcake}" />
    </Rectangle.Fill>
 </Rectangle>

This is the resource icons.xmlfile in my app.

这是icons.xml我的应用程序中的资源文件。

<Canvas Width="48" Height="48" Clip="F1 M 0,0L 48,0L 48,48L 0,48L 0,0" x:Key="appbar_cupcake">
    <Path Width="24" Height="25" Canvas.Left="13" Canvas.Top="11" Stretch="Fill" Fill="{DynamicResource BlackBrush}" Data="F1 M 32,14C 33.1046,14 34,14.8954 34,16C 34,16.3643 33.9026,16.7058 33.7324,17L 34,17C 35.1046,17 36,17.8954 36,19C 36,20.1046 35.1046,21 34,21L 35,21C 36.1046,21 37,21.8954 37,23C 37,24.1046 36.1046,25 35,25L 15,25C 13.8954,25 13,24.1046 13,23C 13,21.8954 13.8954,21 15,21L 16,21C 14.8954,21 14,20.1046 14,19C 14,17.8954 14.8954,17 16,17L 16.2676,17C 16.0974,16.7058 16,16.3643 16,16C 16,14.8954 16.8954,14 18,14C 19,14 21,12 25,11C 29,14 31,14 32,14 Z M 15,26L 35,26L 32,36L 18,36L 15,26 Z " />
</Canvas>

What I'm doing wrong?

我做错了什么?

回答by Michael Mairegger

If you want to dynamically set the Fillcolor, you can do that by setting the Fillproperty. As you can see, you are already using the Fillproperty for the VisualBrush. Fortunately you can use the VisualBrushalso in the OpacityMaskproperty.

如果要动态设置Fill颜色,可以通过设置Fill属性来实现。如您所见,您已经在将该Fill属性用于VisualBrush. 幸运的是,您也可以VisualBrush在该OpacityMask属性中使用 。

<Rectangle Fill="Black">
    <Rectangle.OpacityMask>
        <VisualBrush Visual="{StaticResource appbar_cupcake}" Stretch="Fill" />
    </Rectangle.OpacityMask>
</Rectangle>

Hope that helps.

希望有帮助。