Hey all,
I'm kind of new to WPF, and I'm trying to do some specialized data binding. Specifically, I have a DataGrid that is bound to a collection of objects, but then I want the headers of the columns to be bound to a separate object. How do you do this?
I have a couple of classes defined like so:
public class CurrencyManager : INotifyPropertyChanged
{
private string primaryCurrencyName;
private List<OtherCurrency> otherCurrencies;
//I left out the Properties that expose the above 2 fields- they are the standard
//I also left out the implementation of INotifyPropertyChanged for brevity
}
public class OtherCurrency : INotifyPropertyChanged
{
private string name;
private double baseCurAmt;
private double thisCurAmt;
//I left out the Properties that expose the above 3 fields- they are the standard
//I also left out the implementation of INotifyPropertyChanged for brevity
}
Then the important section of XAML is as follows. Assume that I've already bound the Page to a specific object of type CurrencyManager. Note how binding attached to the header of the 2nd DataGridTextColumn is incorrect, and needs to somehow get access to the CurrencyManager object's property PrimaryCurrencyName. That is, the header of the column has the name "PrimaryCurrencyName", and the data in the column is still bound to the property ThisCurAmt for each element of the OtherCurrencies List.
<DataGrid ItemsSource="{Binding Path=OtherCurrencies}" AutoGenerateColumns="False" RowHeaderWidth="0">
<DataGrid.Columns>
<DataGridTextColumn Header="Currency Name" Binding="{Binding Path=Name}"/>
<DataGridTextColumn Binding="{Binding Path=BaseCurAmt}">
<DataGridTextColumn.Header>
<Binding Path="PrimaryCurrencyName"/>
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn Header="Amt in this Currency" Binding="{Binding Path=ThisCurAmt}"/>
</DataGrid.Columns>
</DataGrid>
How do I do this? Thanks!