私はデータグリッドビューに辞書をバインドしたいと思います。
これは、データグリッド コントロールにバインドするプロパティです。
public IDictionary<string, Bill> CellPhoneBills
{
get { return _cellPhoneBills; }
set
{
_cellPhoneBills = value;
NotifyOfPropertyChange(()=>CellPhoneBills);
}
}
これがクラス Bill です。
public class Bill : INotifyPropertyChanged
{
#region Private fields
private string _cellPhoneNo;
private BillData _vps;
#endregion
#region Properties
public string CellPhoneNo
{
get { return _cellPhoneNo; }
set
{
_cellPhoneNo = value;
NotifyPropertyChanged("CellPhoneNo");
}
}
public BillData Vps
{
get { return _vps; }
set
{
_vps = value;
NotifyPropertyChanged("Vps");
}
}
#endregion
#region Constructor
public Bill()
{
Vps = new BillData();
}
#endregion
#region Implementation of INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
#endregion
}
BillData クラス:
public class BillData : INotifyPropertyChanged
{
#region Private fields
private int _time;
private double _price;
private List<Call> _calls;
#endregion
#region Properties
public int Time
{
get { return _time; }
set
{
_time = value;
NotifyPropertyChanged("Time");
}
}
public Double Price
{
get { return _price; }
set
{
_price = value;
NotifyPropertyChanged("Price");
}
}
public List<Call> Calls
{
get { return _calls; }
set
{
_calls = value;
NotifyPropertyChanged("Calls");
}
}
#endregion
#region Constructors
public BillData()
{
Calls = new List<Call>();
}
#endregion
#region Implementation of INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
#endregion
}
ここにxamlがあります:
<Controls:DataGrid
ItemsSource="{Binding Path= Bill, Mode=OneWay,
UpdateSourceTrigger=PropertyChanged}">
<Controls:DataGrid.Columns>
<Controls:DataGridTextColumn IsReadOnly="True"
Binding="{Binding Path=Vps.Price}"
Header="Vps"/>
</Controls:DataGrid.Columns>
</Controls:DataGrid>
しかし、データグリッドは空白です。
辞書の値を配列に変換し、これをデータグリッドにバインドしてみます。
public IList<Bill> Bill
{
get { return CellPhoneBills.Values.ToList();}
}
役に立ちませんでした。
問題の根本とは?