【发布时间】:2017-01-20 17:01:00
【问题描述】:
当我在我的 xaml 中使用 x:Bind 绑定数据时,它可以工作,但是当使用 Binding 代替 x:Bind 执行相同的代码时,它不会。为什么会这样??我读过他们的区别,说一个是运行时和其他编译时间和类似的东西,但这根本没有帮助。任何人都可以在实际水平上帮助我吗??
【问题讨论】:
标签: c# xaml data-binding
当我在我的 xaml 中使用 x:Bind 绑定数据时,它可以工作,但是当使用 Binding 代替 x:Bind 执行相同的代码时,它不会。为什么会这样??我读过他们的区别,说一个是运行时和其他编译时间和类似的东西,但这根本没有帮助。任何人都可以在实际水平上帮助我吗??
【问题讨论】:
标签: c# xaml data-binding
使用 x:bind 只能绑定模型类实例的成员。
//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}}">
....
通过绑定,您可以只绑定模型类实例的一个成员
还可以绑定整个实例(当前对象。不仅仅是它的单个属性)
//you can send only instance property (Gender) to the converter
<DataTemplate x:DataType="Models:Human">
<StackPanelHorizontalAlignment="Stretch" Background="{x:Bind Gender, Converter={StaticResource UnwantedDayColorConverter}}">
【讨论】: