locked
ListBox DataBinding RRS feed

  • Question

  • Hello Friends,

    How does Two Way databinding work in ListBox? I can populate the ListBox but how can I send the selected value into the object. Note that the list is populated from a seperate list then the one tied with the DataContext of the usercontrol.

    Tahir

    Saturday, April 12, 2008 6:25 PM

Answers

  • Hi:

      You can Put a TextBlock (visible) and TextBox (collapsed) into a StackPanel in DataTemplate. Then show the TextBox and hide the TextBlock when clicking the StackPanel.

    Regards

    Tuesday, April 15, 2008 5:01 AM

All replies

  • Hi:

      You can Put a TextBlock (visible) and TextBox (collapsed) into a StackPanel in DataTemplate. Then show the TextBox and hide the TextBlock when clicking the StackPanel.

    Regards

    Tuesday, April 15, 2008 5:01 AM
  • Could you please give me some code example. I am new to Silverlight/WPF/XAML.

    What I am trying to do is to implement two-way databinding with listbox. With TextBox it is simple but I have no clue how it works with a listbox. 

     Thanks.

    Saturday, April 19, 2008 2:13 PM
  • tna55,

    Check out the following tutorial:

    http://silverlight.net/learn/tutorials/databinding.aspx 

    Saturday, April 19, 2008 2:57 PM
  • Thanks for your reply.

     I have read this article already. What I am trying to do is quite simple but it seems difficult in Silverlight. Let me try and explain again.

    I have a business object SomeBusinessObject and one of its property is a foreign key e.g. EmployeeID. Now I want to fill the ListBox with Names of all employess from EmployeeList list. I now want to Bind the EmployeeID with this listbox so that an employee is selected based on EmployeeID and whenever an item is changed in listbox the SomeBusinessObject's EmployeeID is updated. Like we have in Textbox, when you bind it with a property of an object, it automatically gets updated once user change the text.

    I hope my question is clear.

    I would really appreciate help.

    Thanks again.

    Saturday, April 19, 2008 5:37 PM