Caliburn Micro MVVM 获取组合框以显示 ViewModel 屏幕
Caliburn Micro MVVM getting comboBox to display a ViewModel screen
我有一个组合框,可以在 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 但它对我来说没有意义
好的,这就是我解决问题的方法...
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());
}
}
我有一个组合框,可以在 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 但它对我来说没有意义
好的,这就是我解决问题的方法...
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());
}
}