0

我想在数据网格视图上绑定字典。

这是我在数据网格控件上绑定的属性。

    public IDictionary<string, Bill> CellPhoneBills
    {
        get { return _cellPhoneBills; }
        set
        {
            _cellPhoneBills = value;
            NotifyOfPropertyChange(()=>CellPhoneBills);
        }
    }

这是班比尔。

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
}

账单数据类:

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();}
}

它没有帮助。

问题的根源是什么?

4

0 回答 0