绑定实例作为资源 [英] Binding instance as resource
本文介绍了绑定实例作为资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在xaml中有一个非常长且重复的绑定表达。我可以先在资源部分定义它,然后使用DynamicResource或StaticResource引用它吗?像这样的东西:
I have a very long and repeating binding expression in xaml. Can I first define it in resource section and then refer to it using DynamicResource or StaticResource? Something like:
<SomeControl Visibility="{DynamicResource BindingToParentDataContext}">
绑定表达式如下:
{Binding Path=DataContext.SomeProperty, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:SomeParentUserControl}}, Mode=OneWay, Converter={StaticResource booleanToVisibilityConverter}}
推荐答案
What might work is to write a custom markup extension. This should be a good reference.
但是除此之外,您不能像这样预定义标记。根据您的情况,您可以将其中一些放入数据模板中,以供重用。
But besides that, you can't "predefine" markups like that. Depending on your scenario, you might can put some of these into a datatemplate, which you can reuse.
这篇关于绑定实例作为资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文