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

  • Home
  • SEARCH
  • 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 3357106
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:35:38+00:00 2026-05-18T02:35:38+00:00

Why databinding TwoWay don’t work on the text property of a combobox in .net

  • 0

Why databinding TwoWay don’t work on the text property of a combobox in .net 4.0 (it’s working in .net 3.5)?

My code:

I have an xml file like this:

<xml>

  <combobox option="" obs="tralala">
    <option value="here" />
    <option value="there" />
  </combobox>

  <combobox option="blue" obs="">
    <option value="one" />
    <option value="two" />
    <option value="three" />
  </combobox>

</xml>

and I have a ListItem control like that:

<ListBox DataContext="{Binding UpdateSourceTrigger=PropertyChanged}"
         ItemsSource="{Binding UpdateSourceTrigger=PropertyChanged}"
         IsSynchronizedWithCurrentItem="True">
   <ListBox.ItemTemplate>
    <DataTemplate>
      <DockPanel LastChildFill="True">
        <ComboBox MinWidth="75" IsEditable="True"
                  IsReadOnly="False" DockPanel.Dock="Left"
                  DataContext="{Binding Path=Element[combobox ]}"
                  IsSynchronizedWithCurrentItem="False"
                  ItemsSource="{Binding Path=Elements[option], UpdateSourceTrigger=PropertyChanged}"
                  DisplayMemberPath="Attribute[value].Value"
                  Text="{Binding Path=Attribute[option].Value, UpdateSourceTrigger=PropertyChanged}"
                  />
        <TextBox MinWidth="150" AcceptsReturn="False"
                 AcceptsTab="False" TextWrapping="NoWrap"
                 Text="{Binding Path=Attribute[obs].Value, UpdateSourceTrigger=PropertyChanged}" />
      </DockPanel>
    </DataTemplate>
  </ListBox.ItemTemplate>
</ListBox>

Here is the code behind:

XDocument xdXml;

public MyWindow()
{

    xdXml = XDocument.Load(@"C:\file.xml");

    InitializeComponent();

    DataContext = xdXml;

    xdXml.Changed += new EventHandler<XObjectChangeEventArgs>(XdXml_Changed);
}


private void XdXml_Changed(object sender, XObjectChangeEventArgs e)
{
    xdXml.Save(@"C:\fichier.xml");
}

I do like that because I can have a ComboBox with auto-completion with the different custom option for each, but I can write what I want, and the result is in the attribute option of the element <combobox>

It work fine if I target .net 3.5, but only textbox bind if I target .net 4.0

Why?
What can I do?

  • 1 1 Answer
  • 0 Views
  • 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. Editorial Team
    Editorial Team
    2026-05-18T02:35:38+00:00Added an answer on May 18, 2026 at 2:35 am

    Here is the solution for doing this code working with framework 4.0 (I’ve tried to adapt it to your exemple, but i’m not sure. Anyway, this is the idea):

    Change your ListItem control like that:

    <ListBox DataContext="{Binding UpdateSourceTrigger=PropertyChanged}"
             ItemsSource="{Binding UpdateSourceTrigger=PropertyChanged}"
             IsSynchronizedWithCurrentItem="True">
       <ListBox.ItemTemplate>
        <DataTemplate>
          <DockPanel LastChildFill="True">
            <!-- Add this collapsed textbox -->
            <TextBox Visibility="Collapsed" DataContext="{Binding Path=Element[combobox]}" Text="{Binding Path=Text, ElementName=cbxComboBox, UpdateSourceTrigger=PropertyChanged}" TextChanged="TextBox_TextChanged" />
            <!-- Name the Combobox -->
            <ComboBox Name="cbxComboBox" MinWidth="75" IsEditable="True"
                      IsReadOnly="False" DockPanel.Dock="Left"
                      DataContext="{Binding Path=Element[combobox]}"
                      IsSynchronizedWithCurrentItem="False"
                      ItemsSource="{Binding Path=Elements[option], UpdateSourceTrigger=PropertyChanged}"
                      DisplayMemberPath="Attribute[value].Value"
                      Text="{Binding Path=Attribute[option].Value, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
                      />
            <TextBox MinWidth="150" AcceptsReturn="False"
                     AcceptsTab="False" TextWrapping="NoWrap"
                     Text="{Binding Path=Attribute[obs].Value, UpdateSourceTrigger=PropertyChanged}" />
          </DockPanel>
        </DataTemplate>
      </ListBox.ItemTemplate>
    </ListBox>
    

    And your new code behind is:

    XDocument xdXml;
    
    public MyWindow()
    {
    
        xdXml = XDocument.Load(@"C:\file.xml");
    
        InitializeComponent();
    
        DataContext = xdXml;
    
        xdXml.Changed += new EventHandler<XObjectChangeEventArgs>(XdXml_Changed);
    }
    
    
    private void XdXml_Changed(object sender, XObjectChangeEventArgs e)
    {
        xdXml.Save(@"C:\fichier.xml");
    }
    
    // finally, add this event:
    private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
    {
        if (((XElement)((FrameworkElement)sender).DataContext).Attribute("option").Value != ((TextBox)sender).Text)
        {
            ((XElement)((FrameworkElement)sender).DataContext).Attribute("option").Value = ((TextBox)sender).Text;
        }
    }
    

    For understand, take a look at:

    • UIElement.TextInput Event
    • What is the ‘right’ way to allow arbitrary input in a ComboBox?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why DataBinding is not working? <TextBox Text={Binding Path=local:MainWindow.SearchPlayer, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged} /> this is my class:
I'm working with Databinding in ASP.Net 2.0, and I've come across an issue with
I have in my webform many TBs bound to a property in the code
I'm databinding a Repeater and I would like to have access to a variable
How does two-way databinding work in Silverlight when the data source object's properties don't
I have simple issue setting a two-way databinding of a checkbox in Silverlight 3.0.
When doing databinding does one have to implement INotifyPropertyChanged on the datacontext in WPF?
I have a ListBox with databinding. I need to fire an event when a
Possible Duplicate: Using ASP.NET Controls without databinding My previous question yielded few results so
I am trying to do follow DataBinding Property -> DependencyProperty -> Property But i

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.