绑定到一些嵌入式对象属性 [英] Bind to some embedded object properties
本文介绍了绑定到一些嵌入式对象属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个汽车的IEnumerable
:
public IEnumerable<ICars> Cars { get; private set; }
对象车,实际上包含了类型IBrand的另一个对象的引用:
The object "Car" actually contains a reference to another object of type IBrand:
public interface ICar
{
// Parent brand accessor
IBrand Brand { get; set; }
// Properties
int CarId { get; set; }
string CarName { get; set; }
}
该IBrand接口有一些属性:
The IBrand interface has some properties:
public interface IBrand
{
// Properties
string LogoName { get; set; }
string Sector { get; set; }
}
我绑定此车的IEnumerable到DataGrid - 此workds完美的罚款
<DataGrid Name="Cars"
ItemsSource="{Binding}"
SelectedItem="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}, AncestorLevel=2}, Path=SelectedCar, Mode=TwoWay}">
<DataGrid.Columns>
<DataGridTextColumn Header="Car Id"
Binding="{Binding CarId}"
IsReadOnly="True" />
<DataGridTextColumn Header="Car Name"
Binding="{Binding CarName}"
IsReadOnly="True" />
</DataGrid.Columns>
我的问题是,我想结合从品牌的一些特性以及(适用于所有的车),例如像标志。 此synthax不工作,虽然
My problem is that I'd like to bind some properties from the Brand as well (common to all the cars), like for example the logo. This synthax doesn't work though:
<DataGridTextColumn Header="Logo Name"
Binding="{Binding Brand.LogoName}"
IsReadOnly="True" />
这是如何做到这一点任何想法?谢谢!
Any idea on how to do so? Thank you!
推荐答案
当你使用,你需要指定路径虚线路径
明确关键字。这应该工作:
When you use a dotted path you need to specify the Path
keyword explicitly. This should work:
<DataGridTextColumn Header="Logo Name" Binding="{Binding Path=Brand.LogoName}" IsReadOnly="True" />
这篇关于绑定到一些嵌入式对象属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文