【发布时间】:2013-06-24 21:12:55
【问题描述】:
我有一辆汽车IEnumerable:
public IEnumerable<ICars> Cars { get; private set; }
对象“Car”实际上包含对另一个 Ibrand 类型对象的引用:
public interface ICar
{
// Parent brand accessor
IBrand Brand { get; set; }
// Properties
int CarId { get; set; }
string CarName { get; set; }
}
IBrand 接口有一些属性:
public interface IBrand
{
// Properties
string LogoName { get; set; }
string Sector { get; set; }
}
我正在将此 Cars IEnumerable 绑定到 DataGrid - 这非常好:
<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>
我的问题是我还想绑定品牌的一些属性(所有汽车通用),例如徽标。 这个合成器不起作用:
<DataGridTextColumn Header="Logo Name"
Binding="{Binding Brand.LogoName}"
IsReadOnly="True" />
你知道怎么做吗?谢谢!
【问题讨论】: