So, I've got a DataGrid which shows a list of payments.
<DataGrid x:Name="dataGrid" ItemsSource="{Binding Payments}" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="PaymentDate" Binding="{Binding PaymentDate, StringFormat=\{0:d\}}" />
<DataGridTextColumn Header="Amount" Binding="{Binding Amount, StringFormat=\{0:N\}}" />
<DataGridTextColumn Header="Comment" Binding="{Binding Comment}" />
<DataGridTextColumn Binding="{Binding EventCode}" Header="Event Code"/>
<DataGridTextColumn Binding="{Binding DueDate, StringFormat=\{0:d\}}" Header="DueDate"/>
</DataGrid.Columns>
</DataGrid>
This DataGrid is bound to an ObservableCollection of Payment objects.
public class Payment
{
public Guid ID { get; set; }
public DateTime PaymentDate { get; set; }
public decimal Amount { get; set; }
public string Comment { get; set; }
public string EventCode { get; set; }
public DateTime? DueDate { get; set; }
List<Booking> Bookings
{
get { ...magic that retrieves booking info... }
}
}
As you can see, each payment has a property which is a list of Booking objects which show how each payment was allocated.
The Booking object is pretty simple.
public class Booking
{
public string EventCode { get; set; }
public decimal Amount { get; set; }
public DateTime? BookingDate { get; set; }
public string Designation { get; set; }
public string Comment { get; set; }
}
And I have a second DataGrid which should show a list of Booking objects for a selected Payment.
<DataGrid ItemsSource="{Binding SelectedItem.Bookings, ElementName=dataGrid}" AutoGenerateColumns="True" />
What I expected was that whenever I selected a payment item in DataGrid 1, DataGrid 2 would be populated with the details for how that payment was allocated. What I got, however, was an empty details DataGrid.
I know I could tie the SelectedItem property to a property in my ViewModel and notify my View every time that property is changed, but it seems like DataGrid 2 should know that the SelectedItem property of DataGrid 1 has been changed automatically. Am I asking too much, or am I just doing it wrong?