This example is admittedly a bit contrived, but I'm doing something similar. Let's say I have the following simple classes:
public class Person { public string Name { get; set; } public List<Alias> Aliases { get; set; } } public class Alias { public string AliasName { get; set; } }
And let's say that I have Xaml with the LayoutRoot and DataGrid grid, where I want to access the Name property in the DataGrid instead of the alias properties, for example, in the second column:
<Grid x:Name="LayoutRoot" DataContext="PersonInstance"> <DataGrid ItemsSource="{Binding Aliases}"> <DataGrid.Columns> <data:DataGridTextColumn Header="AliasName" Binding="{Binding AliasName, Mode=TwoWay}"/> <data:DataGridTextColumn Header="Name" Binding="{Binding ../Name, Mode=TwoWay}"/> </DataGrid.Columns> </DataGrid> </Grid>
It is intuitive how I try to associate the name, but of course it looks stupid. Is there something similar when specifying a path, or are you forced to get a relative source before the LayoutRoot data context. If you need, what is the most effective way?
data-binding relative-path wpf
Ben mcintosh
source share