原文:Bind Enum to Combobox.SelectedIndex Do you mean that you want to bind a variable (not a property) to ComboBox.SelectedIndex? If so, I think that the better method to do this is bind a property to ComboBox.SelectedItem. The following example shows…
当使用MVVM时,相信你和我一样经常有这样的需求: 在ViewModel里定义了一个Enum,它必然是对应UI上的一个ListControl作为不同选项. 有一种做法是使用Converter,将Enum的Values取出用作Binding.但是当Converter数量增长时,你会想是能少一个Converter就少一个. 这里会介绍另一种可以省略一个Converter的做法来实现将Enum的Values取出用作Binding. How to use: Step 1: 添加一个ObjectDataP…
0. 准备测试数据 0.1 : 枚举 using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace MvcApplication.Models { public enum YesOrNo { 否 = 0, 是 = 1 } } 0.2 : 对应实体类及表sql using System; using System.Collections.Generic; using Sy…