Reputation: 853
I have a Cars IEnumerable
:
public IEnumerable<ICars> Cars { get; private set; }
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; }
}
The IBrand interface has some properties:
public interface IBrand
{
// Properties
string LogoName { get; set; }
string Sector { get; set; }
}
I am binding this Cars IEnumerable to a DataGrid - this workds perfectly fine:
<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>
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!
Upvotes: 0
Views: 203
Reputation: 49985
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" />
Upvotes: 2