1. 程式人生 > >WPF中comboBox元件如何繫結裡面有Description的列舉

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

開啟的有點慢,請耐心等待,然後自己去試一下吧