我正在尝试在xaml中创建一个渐变画笔数组,但我想将每个数组元素指回一个静态资源,即渐变画笔。所以,到目前为止,我还是无法做到这一点。有人可以就如何实现这个目标提供指导吗?
我想将它们添加到x:Array但是指向资源而不是必须重新定义画笔,因为我必须在这里做。除了数组之外,我还在几个地方使用画笔,所以我只想定义画笔一次。
<LinearGradientBrush x:Key="OrangeLinearGradientBrush" StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Offset="0" Color="#FFF7941D" />
<GradientStop Offset="1" Color="#FFF26522" />
</LinearGradientBrush>
<LinearGradientBrush x:Key="RedLinearGradientBrush" StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Offset="0" Color="#F26263" />
<GradientStop Offset="1" Color="#B80303" />
</LinearGradientBrush>
<x:Array x:Key="BrushArray" Type="LinearGradientBrush">
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Offset="0" Color="#FFF7941D" />
<GradientStop Offset="1" Color="#FFF26522" />
</LinearGradientBrush>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Offset="0" Color="#F26263" />
<GradientStop Offset="1" Color="#B80303" />
</LinearGradientBrush>
</x:Array>
答案 0 :(得分:0)
您可以使用StaticResourceExtensions:
<x:Array x:Key="BrushArray" Type="LinearGradientBrush">
<StaticResourceExtension ResourceKey="OrangeLinearGradientBrush"/>
<StaticResourceExtension ResourceKey="RedLinearGradientBrush"/>
</x:Array>