Caliburn Micro MVVM获取comboBox以显示ViewModel屏幕

时间:2017-10-04 13:06:58

标签: mvvm combobox caliburn.micro

我有一个组合框在ViewModel中完美地显示其中的列表但是我希望它能够在选择列表中的选定项目时触发ViewModel屏幕,我只想从列表中选择一个这个? 这就是我在ChooseView中的内容:

<ComboBox x:Name="CatalogName1" SelectedItem="{Binding SelectedCatalog1}" Style="{DynamicResource appComboBox}" Grid.Row="1" Grid.Column="1"  >
    </ComboBox>

并在ChooseViewModel:

public List<string> CatalogName1
    {
        get
        {
            return new List<string> { "New", "Replace", "Extended", "Nothing", "ShowScreen" };
        }


    }

     private string selectedCatalog1;
    public string SelectedCatalog1
    {
        get
        {
            return this.selectedCatalog1;
        }

        set
        {
            this.selectedCatalog1 = value;
            this.NotifyOfPropertyChange(() => this.SelectedCatalog1);
        }
    }

组合列表中的“ShowScreen”应该显示ShowScreenViewModel,但我尝试使用getter setter,这对我没有意义

1 个答案:

答案 0 :(得分:1)

好的,这是我解决问题的方法......

private string selectedCatalog1;
    public string SelectedCatalog1
    {
        get
        {
            return selectedCatalog1;
        }
        set
        {
            selectedCatalog1 = value;
            ValidateValue(value);
            NotifyOfPropertyChange(() => SelectedCatalog1);
        }
    }
    private void ValidateValue(string s)
    {
        if (s == "ShowScreen")
        {
            ActivateItem(new ShowScreenViewModel());
        }
    }