2016-07-25 3 views
0

J'ai un problème avec la liaison dans ComboBox. J'ai cherché dans Google et ainsi, mais je n'ai pas pu trouver la réponse.Lier la propriété combobox de l'élément sélectionné dans la zone de liste déroulante au champ

J'ai forme silverlight avec combobox comme ceci:

<ComboBox x:Name="FirmBox" 
      Grid.Row="23" 
      Grid.Column="1" 
      Grid.ColumnSpan="2" 
      Margin="5,5,5,0" 
      SelectedValuePath="{Binding Path=Value, Mode=TwoWay}" 
      SelectedItem="{Binding Path=Firm, Mode=TwoWay}"> 
    <ComboBox.ItemTemplate> 
     <DataTemplate> 
      <StackPanel Orientation="Horizontal"> 
       <TextBlock Text="{Binding Path=Value}"/> 
       <TextBlock Text="{Binding Path=Key}"/> 
      </StackPanel> 
     </DataTemplate> 
    </ComboBox.ItemTemplate> 
</ComboBox> 

Et le ItemsSource est un

ObservableCollection<KeyValue<String, KeyValue<String, String>>> 

J'ai donc compris comment afficher dans le bon sens, mais je n » Je sais comment lier l'élément sélectionné à mon champ KeyValuePair<String, String> . Cela ne me semble pas évident. J'ai donc besoin de lier la valeur de l'élément sélectionné à mon champ et je ne sais pas comment le faire.

Merci.

Répondre

0

La solution était simple comme toujours:

SelectedValuePath="Value" 
SelectedValue="{Binding Path=Firm, Mode=TwoWay}">