Silverlight中使用MVVM(9)-绑定Enum类型数据
<div id="cnblogs_post_body">Silverlight中使用MVVM(1)--基础
Silverlight中使用MVVM(2)—提高
Silverlight中使用MVVM(3)—进阶
Silverlight中使用MVVM(4)—演练
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与枚举类型绑定的一种方式:
首先看张效果图:
http://images.cnblogs.com/cnblogs_com/626498301/201205/201205221054455551.png
我们要做的事情很简单,就是将枚举的属性值绑定到RadioButton上,有了本系列前面几篇文章的基础,我相信建立一个MVVM的框架已经了然于心了,所以本篇的重点集中
在ViewModel和View中.
首先我们构建一个枚举类型,ViewModel代码如下:
<div id="codeSnippetWrapper"> <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"> 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 }
页:
[1]