x:xaml 中的意思 [英] x: meaning in xaml

查看:25
本文介绍了x:xaml 中的意思的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到很多像

或者喜欢

<BooleanToVisibilityConverter x:Key="boolToVis" />

为什么需要 x: 以及它给了我什么.

Why the x: is needed and what it gives me.

<DockPanel.Resources>
  <c:MyData x:Key="myDataSource"/>
</DockPanel.Resources>

这里我们还有 c:

感谢帮助

推荐答案

它只不过是 XML 不同命名空间的快捷方式.您可以根据需要选择它们.如果您查看 XAML 中的上面几行,您会发现该行:

It is nothing more than shortcuts to the different namespaces for XML. You can choose them as you like. If you look at the upper lines in your XAML you will find the line:

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

例如将 'x' 更改为 'wpf',您将看到您需要更改所有的 'x:'将代码中的前缀添加到 'wpf:' 以使其编译.

Change the 'x' to 'wpf' for instance and you will see that you need to change all the 'x:' prefixes in your code to 'wpf:' to make it compile.

'c:' 前缀引用您自己的代码.假设您有一个编译为 MyLib.dll 的类库.该库包含一个名为 MyData 的类.为了能够引用 MyData 类,您需要类似于:

The 'c:' prefix references code of your own. Say you have a class library that compiles to MyLib.dll. This library contains a class named MyData. To be able to reference the MyData class you need something like:

xmlns:c="clr-namespace:MyClasses;assembly=MyLib"

在您的 XAML 标头中.

in your XAML header.

然后,您可以使用 c:MyData 在 XAML 中引用 MyData 类.但是您可以完全自由地将c"更改为myfabulousclasses"或您喜欢的任何其他内容.

You can then reference the MyData class in you XAML with c:MyData. But you are entirely free to change the 'c' to 'myfabulousclasses' or anything else you fancy.

这样做的目的是什么?区分同名但属于不同dll的类或成员.

The purpose of this? To distinguish classes or members that have the same name, but belong to different dll's.

这篇关于x:xaml 中的意思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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