XAML 2009 - X:参考 - 任何缺点使用呢? [英] XAML 2009 - x:Reference - Any downside to using this?

查看:193
本文介绍了XAML 2009 - X:参考 - 任何缺点使用呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只有几个月的经验,XAML,往往有困难的时候决定如何绑定在我的XAML中不同的地方定义或参考因素。我最近直径×跑:参考文献,我的理解是新与2009年的XAML和.NET 4

I only have a few months experience with XAML and often have a difficult time determining how to bind to or reference elements defined in various places in my XAML. I recently ran across X:Reference, which I understand is new with XAML 2009 and .NET 4.

例如,假设我想绑定到一个名为DisplayIndi​​cator,一个元素是在我的XAML其他地方定义的财产器isChecked。 X:参考允许我做它,如下所示:

For example, assume I am trying to bind to the IsChecked property of an element named DisplayIndicator, which is defined elsewhere in my XAML. X:Reference allows me to do it as follows:

{绑定源= {X:参考DisplayIndi​​cator},路径=}器isChecked

这似乎是一个简单的方法(和preferred的方式?)来引用我的XAML中声明的几乎所有元素。难道我错了吗?是否有一个缺点用这个?

This seems like an easy way (and preferred way?) to reference almost any element declared in my XAML. Am I wrong about this? Is there a downside to using this?

非常感谢。

推荐答案

X:参考文档

在WPF和2006年的XAML,元素引用是由具有约束力的ElementName的框架级功能解决。对于大多数WPF应用程序和方案,结合的ElementName应该仍然可以使用。例外情况的一般性指导可能包括在有数据的上下文或其他范围界定方面的考虑,使数据绑定的情况下,不切实际,在不涉及标记编译。

In WPF and XAML 2006, element references are addressed by the framework-level feature of ElementName binding. For most WPF applications and scenarios, ElementName binding should still be used. Exceptions to this general guidance might include cases where there are data context or other scoping considerations that make data binding impractical and where markup compilation is not involved.

我也只用 X:参考如果的ElementName 是不是一种选择。有一件事在这里万变不离其宗的是, X:参考是相当挑剔的周期性的依赖是不是这样的ElementName ;所以这将是一个缺点。

I also only use x:Reference if ElementName is not an option. One thing left unmentioned here is that x:Reference is rather picky with cyclical dependencies which is not the case for ElementName; so that would be a downside.

这篇关于XAML 2009 - X:参考 - 任何缺点使用呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆