locked
Link/Bind Label to ComboBox RRS feed

  • Question

  • I have a ComboBox which is bound to an ObservableCollection that has three fields.

    Currently, the 3rd field of the ObservableCollection is bound to ToolTip of the ComboBox. But, I want it to be bound to a Label so that whenever the user selects a new item in the combo, the label updates. How do I do that?

    Thanks.

     

    Wednesday, February 1, 2012 6:58 AM

Answers

  • <Label Content="{Binding SelectedItem.Property3, ElementName=Combobox1}" />

     

    Point the binding at the combo by giving it a name and referring to ElementName in the binding.

    Bind to the combo box's SelectedItem property, then you can reference the item (object) properties directly.


    Regards,

    Pedro


    • Edited by Pete LakerMVP Wednesday, February 1, 2012 9:58 AM
    • Marked as answer by Jay6447 Wednesday, February 1, 2012 10:18 AM
    Wednesday, February 1, 2012 9:58 AM

All replies

  • Could you show your observablecollection and the xaml (combobox & label) please...
    Wednesday, February 1, 2012 9:44 AM
  • <Label Content="{Binding SelectedItem.Property3, ElementName=Combobox1}" />

     

    Point the binding at the combo by giving it a name and referring to ElementName in the binding.

    Bind to the combo box's SelectedItem property, then you can reference the item (object) properties directly.


    Regards,

    Pedro


    • Edited by Pete LakerMVP Wednesday, February 1, 2012 9:58 AM
    • Marked as answer by Jay6447 Wednesday, February 1, 2012 10:18 AM
    Wednesday, February 1, 2012 9:58 AM
  • Hey Jay, good day to you.

    I believe you may check the following approach:

    <label Content="{Binding ElementName=myComboBox, Path=SelectedItem.Field3}" ..... />
    

    I hope this helps.


    Please, mark my reply as Answer if it helps or vote it up if it gives a key to the solution.
    Thanks in advance and good luck.
    Ahmed M. Gamil
    "It is not titles that honor men, but men that honor titles."
    Wednesday, February 1, 2012 10:00 AM