2011-07-13 24 views
1

Silverlight ToolkitのDataFormコントロールがあり、その中にComboBoxフィールドがあります。コンボボックスの選択された値は、IEditableクラスのプロパティの1つにバインドする必要があります。たとえば、 "H.S."が選択されると、私の財産の価値はH.S.になります。ただし、バインディングによってmyプロパティの値がSystem.Windows.Controls.ComboBoxItemに変更されます。私がSelectedItemプロパティを代わりに使用すると、stackoverflowに関する他の同様の質問で示唆されているように、結果は同じです。 ComboBoxのSelectedValueプロパティを他のプロパティにバインドする方法は?ここに私のXAMLは、(ItemSourceがC#コードでページのコンストラクタで設定されている)である:事前にComboBoxのSelectedValueプロパティを文字列プロパティにバインドする方法はありますか?

<toolkit:DataForm 
        Name="dataForm" 
        ItemsSource="{Binding}" 
        AutoGenerateFields="False" 
        Margin="150, 0, 150, 0" 
        CommitButtonContent="Next" 
        CancelButtonContent="Clear" 
        CommandButtonsVisibility="Commit, Cancel"> 
        <StackPanel> 
         <toolkit:DataField LabelPosition="Top"> 
          <ComboBox SelectedValue="{Binding Degree, Mode=TwoWay}"> 
           <ComboBoxItem Content="H.S." /> 
           <ComboBoxItem Content="B.S./B.A." /> 
           <ComboBoxItem Content="M.S./M.A." /> 
           <ComboBoxItem Content="Ph. D." /> 
           <ComboBoxItem Content="M.D." /> 
          </ComboBox> 
         </toolkit:DataField> 
        </StackPanel> 
</toolkit:DataForm> 

感謝。すべてのComboBoxコントロールのプロパティの良い説明のため

答えて

4

チェックこの記事をアウト:http://johnpapa.net/binding-to-silverlight-combobox-and-using-selectedvalue-selectedvaluepath-and-displaymemberpath

は、例えばコンテンツへSelectedValuePathプロパティを設定してみてください:

<ComboBox SelectedValue="{Binding Degree, Mode=TwoWay}" SelectedValuePath="Content">  
<ComboBoxItem Content="H.S." /> 
<ComboBoxItem Content="B.S./B.A." /> 
<ComboBoxItem Content="M.S./M.A." /> 
<ComboBoxItem Content="Ph. D." /> 
<ComboBoxItem Content="M.D." /> 
</ComboBox> 
関連する問題