我有一个组合框在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,这对我没有意义
答案 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());
}
}