x:绑定和绑定之间的区别 [英] Difference between x:Bind and Binding

查看:115
本文介绍了x:绑定和绑定之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在xaml中使用x:Bind绑定数据时,它可以工作,但是当使用Binding代替x:Bind执行相同的代码时,则不能。为什么会这样?我读过他们的区别,说一个是运行时,其他是编译时之类的东西,但这根本无济于事。谁能在实践上帮助我?

When I bind data using x:Bind in my xaml it works, but when the same code is executed using Binding in place of x:Bind, it doesn't. Why does this happen ?? I have read their difference saying one is runtime and other compile time and stuff like that but that doesn't help at all. Can anyone help me on a practical level??

推荐答案

使用x:bind只能绑定模型类实例的成员。

using x:bind you can bind only a member of model class instance.

 //sends whole current instance to the converter.
//(note: yes you see correct. no property is attached after Binding keyword
  ....
<DataTemplate x:DataType="Models:Human">
<StackPanel Background="{Binding Converter={StaticResource UnwantedDayColorConverter}}">
 ....

通过绑定,您只能绑定模型类instance
的成员

,也可以绑定整个实例(当前对象,而不仅仅是其单个属性)

via Binding you can bind only a member of model class instance
and also you can bind whole instance (current object. not just its single property)

 //you can send only instance property (Gender) to the converter
 <DataTemplate x:DataType="Models:Human">
                <StackPanelHorizontalAlignment="Stretch" Background="{x:Bind Gender, Converter={StaticResource UnwantedDayColorConverter}}">

这篇关于x:绑定和绑定之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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