视图模型之间的ComboBox绑定

时间:2019-04-09 14:39:31

标签: c# mvvm data-binding

我在另一个ViewModel(排序)中有一个ViewModel(排序图)。我想在排序中使用ComboBox来选择在SortingChart中使用的金额。如何从另一个ViewModel

使用组合框

代码隐藏排序:

public class vmSorting : VMBase
{
    //The ComboBox I want to use in the other vm.
    private ComboBox _SelectTop;
    public ComboBox SelectTop
    {
        get { return _SelectTop; }
        set { _SelectTop = value; NotifyPropertyChanged(); }
    }

    //The content in which the (SortingChart) is loaded.
    private object _MyContent;
    public object MyContent
    {
        get { return _MyContent; }
        set { _MyContent = value; NotifyPropertyChanged(); }
    }

    //For the Update button.
    private RelayCommand _cmdUpdate;
    public ICommand Update
    {
        get
        {
            if (_cmdUpdate == null)
                _cmdUpdate = new RelayCommand(param => this.Button_Click_Update(param));
            return _cmdUpdate;
        }
    }

    private void Button_Click_Update(object sender)
    {
        if (sender as string == "UpdateChart")
            MyContent = new AlarmsTopSortingChart();
    }
}

代码行为排序表:

public class vmSortingChart : VMBase
{
    //Here I want to use the selecteditem from the combobox in (Sorting)
}

0 个答案:

没有答案