Binding the Combobox SelectedValue to a textbox
2 answers
<ComboBox x:Name="MyComboBox">
<ComboBoxItem>12</ComboBoxItem>
<ComboBoxItem>13</ComboBoxItem>
<ComboBoxItem>14</ComboBoxItem>
<ComboBoxItem>15</ComboBoxItem>
</ComboBox>
<TextBox Text="{Binding Path=SelectedValue.Content, ElementName=MyComboBox}" />
Since the elements in ComboBox
are of type ComboBoxItem
, I used the property Content
to get the real value. You must use any property exposed by the objects in ComboBox
(use nothing if it is already a list of strings).
+8
source to share
This is for a list box, not a combobox, but it should be roughly the same code:
private void *lstProducts*_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
*currentlabel*.Content = *lstProducts*.SelectedValue.ToString();
}
The cursed bits are the names of the control.
Hope it helps ...
-1
source to share