【问题标题】:How to do a binding in Xaml?如何在 Xaml 中进行绑定?
【发布时间】:2012-02-02 04:36:11
【问题描述】:

我在下面有一个 Linq 查询,其中的“产品”在 XML 文件中包含子元素“名称”和“价格”。

var queryAllProducts = from product in products 
select new { 
    Product = product 
,   PriceEuro = UsdToEuro(product.PriceUsd) 
}; 

在我的 xaml 文件中,我可以使用

将 Textblock 绑定到 PriceEuro
<TextBlock Text= "{Binding PriceEuro}" />

如何将 TextBlock 绑定到“名称”? Text = "{Binding Product.Name}" 对我不起作用。 谢谢。

【问题讨论】:

    标签: xml linq xaml data-binding


    【解决方案1】:
    Text="{Binding Path=Product.Name}"
    

    使用路径。

    【讨论】:

    • 我尝试了 Path,但它对我不起作用。如果我只使用“{Binding Product}”,那么它会显示整个节点(包括名称和价格)。如果我使用“Binding Path=Food}”,结果相同。谢谢。
    • 澄清:“Binding Product”与“Binding Path=Product”作用相同,但“Binding Product.Name”或“Binding Path=Product.Name”不起作用。
    猜你喜欢
    • 2012-02-11
    • 2011-06-12
    • 1970-01-01
    • 1970-01-01
    • 2016-03-31
    • 2018-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多