Я немного новичок в WPF и пытаюсь выполнить какое-то специализированное связывание данных.В частности, у меня есть DataGrid, который связан с коллекцией объектов, но затем я хочу, чтобы заголовки столбцов были связаны с отдельным объектом.Как вы это делаете?
У меня есть пара классов, определенных так:
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
}
Тогда важный раздел XAML выглядит следующим образом.Предположим, что я уже связал страницу с конкретным объектом типа CurrencyManager.Обратите внимание, что привязка, прикрепленная к заголовку 2nd DataGridTextColumn, является неправильной и должна каким-то образом получить доступ к свойству объекта CurrencyManager PrimaryCurrencyName.То есть заголовок столбца имеет имя «PrimaryCurrencyName», а данные в столбце по-прежнему привязаны к свойству ThisCurAmt для каждого элемента списка OtherCurrencies.
<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>
Как это сделать?Спасибо!