Silverlight中使用MVVM(5)-Command II
Silverlight中使用MVVM(6):AutoComplteBox的异步过滤
Silverlight中使用MVVM(7):DataGrid中触发Button的Click事件
Silverlight中使用MVVM(8)-使用AttachedProperty关闭ChildWindow
在实际开发程序的过程中,不乏处理枚举类型的情形, 比如在Code-Behind的方式下处理RadionButton是很容易的,但是如果在纯MVVM模式下通过绑定的方式
可能需要你花费不少的时间,本文提供MVVM模式下处理RadionButton与枚举类型绑定的一种方式:
首先看张效果图:
我们要做的事情很简单,就是将枚举的属性值绑定到RadioButton上,有了本系列前面几篇文章的基础,我相信建立一个MVVM的框架已经了然于心了,所以本篇的重点集中
在ViewModel和View中.
首先我们构建一个枚举类型,ViewModel代码如下:
public class ShellViewModel :PropertyChangedBase,IShell
{
private SwapDuteType _currentSwapOffDuteType;
public SwapDuteType CurrentSwapOffDuteType
{
get { return _currentSwapOffDuteType; }
set { _currentSwapOffDuteType = value;
NotifyOfPropertyChange(() =>CurrentSwapOffDuteType );
}
}
public ShellViewModel()
{
_currentSwapOffDuteType = SwapDuteType.TM;
}
}
public enum SwapDuteType
{
TM, AM,PM
}