Reputation:
I have a TextBox
and a ComboBox
. I want to bind ComboBox
the selected value to text in the TextBox
.
Please help.
Thanks
Upvotes: 2
Views: 10619
Reputation: 13015
<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 items in the ComboBox
are of type ComboBoxItem
, I used the Content
property to get the real value. You should use whatever property exposed by the objects in your ComboBox
(use nothing if it already is a list of strings).
Upvotes: 8
Reputation: 605
This is for a listbox, not a combobox, but it should be pretty much the same code:
private void *lstProducts*_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
*currentlabel*.Content = *lstProducts*.SelectedValue.ToString();
}
The italicized bits are the names of the control.
Hope it helps...
Upvotes: -1