开发者

Bind IDictionary<string, object> on datagrid control in WPF

i would like bind idictionary on datagrid view.

Here is property which I bind on datagrid control.

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

Here is class 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 class:

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
开发者_Python百科        {
            _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
}

Here is 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>

But datagrid is Blank.

I try convert dictionary value to array and bind this on datagrid.

public IList<Bill> Bill
{
    get { return CellPhoneBills.Values.ToList();}
}

It didnt help.

What is root of problem?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜