【问题标题】:Difference between x:Bind and Binding [duplicate]x:绑定和绑定之间的区别[重复]
【发布时间】:2017-01-20 17:01:00
【问题描述】:

当我在我的 xaml 中使用 x:Bind 绑定数据时,它可以工作,但是当使用 Binding 代替 x:Bind 执行相同的代码时,它不会。为什么会这样??我读过他们的区别,说一个是运行时和其他编译时间和类似的东西,但这根本没有帮助。任何人都可以在实际水平上帮助我吗??

【问题讨论】:

标签: c# xaml data-binding


【解决方案1】:

使用 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}}">

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-20
    • 2013-09-20
    • 1970-01-01
    • 1970-01-01
    • 2016-09-17
    • 2011-05-21
    • 2013-06-14
    • 1970-01-01
    相关资源
    最近更新 更多