使用存储在ResourceDictionary中的画笔

问题描述 投票:0回答:2

我是WPF新手,我想创建一个程序范围的Brush,我可以一遍又一遍地引用。我在ResourceDiditonary中有完整定义的画笔。

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options">
   <DrawingBrush x:Key="rg1024_metal_effect" Stretch="Uniform">

我已将此添加到app.xaml。

 <Color x:Key="SteelBrush">#FFFFFF</Color>
 <SolidColorBrush x:Key="AppBrush" Color="{StaticResource rg1024_metal_effect}"/>

但是我得到了错误:

“ rg1024_metal_effect无法解决”

我知道这应该很容易,但是对于像我这样的新生-并不是那么容易。

wpf brush
2个回答
1
投票
如果要在Color中使用AppBrush,则需要像<SolidColorBrush x:Key="AppBrush" Color="{StaticResource SteelBrush}"/>那样定义它>

如果您想将此画笔添加到按钮,则可以使用相同的方式,例如<Button Background="{StaticResource SteelBrush}"/>或在资源字典中为Style创建s Button


0
投票
[如果您在名为[Dictionary1.xaml]的ResourceDictionary中定义资源,而您想从另一个ResourceDictionary中定义的另一个资源(例如App.xaml)中引用该资源,则应合并Dictionary1.xaml转换为App.xaml
© www.soinside.com 2019 - 2024. All rights reserved.