I'm having trouble with a datagrid and I'm wondering if I can make a binding work a certain way. If I can, it would save me from some heavy refactoring that wouldn't really be appropriate.
Anyway, in the below grid I have the main DataGrid columns/rows as well as a RowDetailsTemplate for the sub-rows. The main DataGrid is bound to the Positions collection and the RowDetailsTemplate is bound to the Taxlots collection. Items in the Taxlots collection do not have a Description or Ticker property, whereas items in the Positions collection do.
Is it possible to bind the Ticker and Description columns in the RowDetailsTemplate to the respective columns in the main DataGrid?
Simplified XAML below:
<DataGrid x:Name="SecurityDataGrid"
ItemsSource="{Binding Positions,
NotifyOnSourceUpdated=True,
UpdateSourceTrigger=PropertyChanged}">
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<DataGrid ItemsSource="{Binding Taxlots}">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Ticker}"/>
<DataGridTextColumn Binding="{Binding Description}"/>
<DataGridTextColumn Binding="{Binding Shares}"/>
</DataGrid.Columns>
</DataGrid>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
<DataGrid.Columns>
<DataGridTextColumn Width="Auto" Header="Ticker" Binding="{Binding Path=Ticker, Mode=OneWay}"
TextOptions.TextFormattingMode="Display" />
<DataGridTextColumn Width="Auto" Header="Description" Binding="{Binding Path=Description, Mode=OneWay}"
TextOptions.TextFormattingMode="Ideal" />
<DataGridTextColumn Width="Auto" Header="Shares" Binding="{Binding SharesOwned, Mode=OneWay, Converter={StaticResource DecimalToStringConverter}}"
CellStyle="{StaticResource CellStyleRight}" />
</DataGrid.Columns>
</DataGrid>
RelativeSourcemay work. - CodingYoshi