Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 186661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:41:10+00:00 2026-05-11T15:41:10+00:00

I have a ObservableCollection that’s bound to a ListBox in WPF. I want the

  • 0

I have a ObservableCollection that’s bound to a ListBox in WPF. I want the ListBox to be editable, and for the editing changes to be saved to the collection. Since WPF doesnt provide an editable listbox, I’ve tried creating my own by changing the ListBox.ItemTemplate.

<ListBox.ItemTemplate>     <DataTemplate>                               <TextBox Name='EditableText' Text='{TemplateBinding Content}'/>     </DataTemplate> </ListBox.ItemTemplate> 

Changing the ItemTemplate gives me editable boxes, but any changes to the textboxes dont get saved to the ObservableCollection. Is there a way to have an editable ListBox with two way binding?

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T15:41:11+00:00Added an answer on May 11, 2026 at 3:41 pm

    You cannot do it this way.

    To achieve that kind of trick, you would need your items to be ‘holder classes’ that expose a property you can bind your textbox to.

    To understand it, imagine the following pseudo sequence of calls:

    class ListBox {   Bind(Items)   {     foreach(var item in Items)     {       DataTemplate Template = LoadTemplateForItem(item.GetType()); // this is where your template get loaded       Template.Bind(item); //this is where your template gets bound     }   } } 

    Your template (the DataTemplate with the listbox) is loaded and the item (which I assume is a string in your case) gets passed in. At this point, it only knows the string, and cannot influence anything upwards. A two-way binding cannot influence the collection because the template does not know in which context it is being used, so it cannot reach back to the original collection and modify its contents. For that matter, this is the same thing for the TextBox. If it is not given a conainer and a property name, it has nowhere to ‘store back’ the changes. This basically the same as passing a string into a function call. The function cannot change which string was passed in (ignoring tricks such as by-reference argument passing).

    To get back to your case, you need to build a collection of objects which expose a property containing the value that needs to be edited:

    public class MyDataItem {   string Data { get; set;} } 

    Then you can bind your ListBox to a collection of those items and modifiy your datatemplate:

    <ListBox.ItemTemplate>     <DataTemplate>                                                           <TextBox Name='EditableText' Text='{Binding Data, Mode=TwoWay}'/>     </DataTemplate> </ListBox.ItemTemplate> 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF ItemsControl that is bound to an ObservableCollection. The XAML: <ItemsControl
I have a WPF listbox control that is declaratively bound to a textbox. The
I have an ObservableCollection that is bound to a DataGrid where I want the
I have an ObservableCollection that I want to bind to my listbox... lbRosterList.ItemsSource =
i have ObservableCollection with 100 records. now i want to get split that collection
I have an ObservableCollection of addresses that I am binding to a ListBox. Then
I have an ObservableCollection<Object> that contains two different types. I want to bind this
I have the listBox and a ObservableCollection. The listBox.ItemSource (listNotify.ItemSource) is set to that
I noticed that ObservableCollection in WPF reflects changes in GUI only by adding or
I have a WPF UserControl with a ListBox and ContentPanel. The ListBox is bound

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.