【发布时间】:2012-05-02 18:28:32
【问题描述】:
我试图弄清楚如何将 DataGrid 的数据源绑定到“单元格”的 ObservableCollection。特别是,我有一个 ObservableCollection 包含以下类的实例:
public class Option : INotifyPropertyChanged
{
public Option()
{
}
// +-+- Static Information +-+-
public double spread = 0;
public double strike = 0;
public int daysToExpiry = 0;
public int put_call; // 0 = Call, 1 = Put
// Ticker References
public string fullTicker = "";
public string underlyingTicker = "";
//+-+-Properties used in Event Handlers+-+-//
private double price = 0;
public double Price
{
get { return price; }
set
{
price = value;
NotifyPropertyChanged("Price");
}
}
//+-+-+-+- Propoerty Changed Event & Hander +-+-+-+-+-//
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
}
在我的 DataGrid 上,我想显示这些类(我在每个单元格中使用 TemplateColumns、Price 和 'strike' 变量),以便它们按“underlyingTicker”[这是一个 4 个字符串]和按“spread” [采用背景编码中定义的 6 个可能值中的 1 个]。
目前,当我将 DataGrid 的 DataContext 绑定到 ObservableCollection 时,它会将每个“选项”显示为一行 - 我无法弄清楚如何指定将这些对分组的内容...
这就是我的数据网格现在的样子:
非常感谢 - kcross!
【问题讨论】:
-
您的 DataGrid 的 ItemSource={Binding ...} 是什么样的,以及您的列的至少一个代码示例及其绑定?还有你所说的精确是什么意思:“我不知道如何指定将成对分组的内容”