WPF中comboBox组件如何绑定里面有Description的枚举

原文:https://blog.csdn.net/qq_31298129/article/details/53404983 

先贴上自己的枚举

  

  用的是mvvm框架   

  首先在view的ComboBox控件里面添加 

   <ComboBox x:Name="comboBox"     ItemsSource="{Binding Path=Genders}" DisplayMemberPath="Value" SelectedValuePath="Key" SelectedValue="{Binding DrugTaker.Gender,Mode=TwoWay}"          HorizontalAlignment="Center" Margin="359,41,401,209" VerticalAlignment="Center" Width="44" Height="22" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>

 从ItemsSource这里开始 到TwoWay那里结束  中间都是你所要添加的

   然后到你对应的viewmodel厘面写下面的东西

  然后就可以在界面看到界面上已经绑定成功了

接下来还有几种实现方法,大家自己去试试吧

 http://stackoverflow.com/questions/58743/databinding-an-enum-property-to-a-combobox-in-wpf

打开的有点慢,请耐心等待,然后自己去试一下吧

猜你喜欢

转载自blog.csdn.net/xionglifei2014/article/details/84999587