ResourceDictionary中的别名或引用 [英] Alias or Reference in ResourceDictionary
本文介绍了ResourceDictionary中的别名或引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找一种在 ResourceDictionary
多个键中提供商品的方法。有没有办法做到?
I'm looking for a way to essentially give an item in a ResourceDictionary
multiple keys. Is there a way to do this?
<DataTemplate x:Key="myTemplate" ... />
<AliasedResource x:Key="myTemplateViaAlias" Target="myTemplate" OR_Target={StaticResource myTemplate} />
当我呼叫 TryFindResource( myTemplateViaAlias)
我想拿出myTemplate。我想我可以自己创建一个 AliasedResource
类,并在从字典中将其取消引用时在代码中对其进行引用,但是如果有内置的,我宁愿不这样做
When I call TryFindResource("myTemplateViaAlias")
I want to get myTemplate out. I suppose I could create an AliasedResource
class myself and dereference it in code when I get it out of the dictionary, but I'd rather not do that if there's a built-in way.
推荐答案
您可以通过动态资源传递资源(请注意,笨拙的UI设计人员不会喜欢它)
You can pipe resources through dynamic resources (note that crappy UI designers won't like it)
<Color x:Key="color">Red</Color>
<DynamicResource x:Key="mycolor" ResourceKey="color"/>
<Rectangle Width="100" Height="100">
<Rectangle.Fill>
<SolidColorBrush Color="{StaticResource color}"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle Width="100" Height="100">
<Rectangle.Fill>
<SolidColorBrush Color="{StaticResource mycolor}"/>
</Rectangle.Fill>
</Rectangle>
这篇关于ResourceDictionary中的别名或引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文