首先,我是 WPF 和 MVVM 的新手。我有一个这样的界面
Interface IItemType
{
bool save()
}
我有三个具体的类,它们是从这个接口继承的
Public Class Type1:IItemType
{
public bool save()
{
//save something with method 1
}
}
Public Class Type2:IItemType
{
public bool save()
{
//save something with method 2
}
}
我的视图中有三个单选按钮(它们将来可以扩展到 4,5 或更多),我想通过选择其中一个单选按钮来选择保存方法(类Type1
或)。Type2
问题是如何将这些 Radios 绑定到我的 ViewModel 以不违反 OCP 等模式设计(因为将来我想添加更多类型和 Radios)?
满足 MVVM 最佳实践设计?
** 编辑 **
想象一下我有以下属性
Public IItemType CurrentType { get; set; }
我想在Type1
选择第一个 Radio 时将 ClassType2
放入 CurrentType 属性,并在选择第二个 Radio 时将 Class 放入 CurrentType 属性,依此类推。