你如何通过XAML引用类? [英] How do you reference a class through xaml?

查看:1179
本文介绍了你如何通过XAML引用类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有没有背后的任何代码XAML文件。我想拥有它引用另一个类的布尔同一个项目。我如何引用其他类的对象(注意这些对象是静态的)。

I have a Xaml file that does not have any code behind. I would like to have it reference another class in the same project for a boolean. How do I reference another classes objects (note those objects are static).

感谢您提前。

推荐答案

使用 X :静态标记扩展,例如(从MSDN获取):

use the x:Static markup extension, for example (taken from MSDN):

<object property="{x:Static prefix:typeName.staticMemberName}" .../>

您需要调整这个以满足您的例子(或包括在问题的更多信息)。
还要注意来自同一个 MSDN页面以下警告:

You'll need to adjust this to suit your example (or include more information in the question). Also note the following warning from the same MSDN page:

您使用WPF程序不包含很多有用的静态属性,最有用的静态属性都支持,如默认XAML命名空间而不需要{:静态X}键入方便的使用转换器。对于静态属性,则必须如下列条件之一为真映射为XAML命名空间的前缀:

The default XAML namespace you use for WPF programming does not contain many useful static properties, and most of the useful static properties have support such as type converters that facilitate the usage without requiring {x:Static} . For static properties, you must map a prefix for a XAML namespace if one of the following is true:


  • 您正在引用类型存在在WPF而不是默认的XAML命名空间WPF的一部分。这是使用 X一个相当常见的场景:静态。例如,你可以用一个 X:静态用XAML命名空间映射到系统CLR命名空间和mscorlib程序集,以引用<$ C $的静态属性参考C>环保类。

  • 您正在引用从自定义组件的类型。

  • 您正在引用一个类型,存在于一个WPF组件,但该类型是未映射到是WPF默认XAML命名空间的一部分的CLR命名空间内。 CLR命名空间到默认XAML命名空间为WPF的映射是由定义在各个WPF组件执行。如果CLR命名空间大多是通常不用于XAML类的定义,如 System.Windows.Threading程序组成可以存在非映射CLR命名空间。

  • You are referencing a type that exists in WPF but is not part of the default XAML namespace for WPF. This is a fairly common scenario for using x:Static. For example, you might use an x:Static reference with a XAML namespace mapping to the System CLR namespace and mscorlib assembly in order to reference the static properties of the Environment class.
  • You are referencing a type from a custom assembly.
  • You are referencing a type that exists in a WPF assembly, but that type is within a CLR namespace that was not mapped to be part of the WPF default XAML namespace. The mapping of CLR namespaces into the default XAML namespace for WPF is performed by definitions in the various WPF assemblies. Non-mapped CLR namespaces can exist if that CLR namespace is composed mostly of class definitions that are not typically intended for XAML, such as System.Windows.Threading.

所以,你可能需要的定义命名空间

xmlns:prefix="clr-namespace:YOURNAMESPACE;assembly=YOURLIB"

这篇关于你如何通过XAML引用类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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