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 7523233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:44:16+00:00 2026-05-30T02:44:16+00:00

I have an issue trying to persist entities to the DB using code-first technique.

  • 0

I have an issue trying to persist entities to the DB using code-first technique. For example of what I am doing you may look at the following MSDN Sample. The app generally works as intended except for one case.

If I have an existing entity and I bind it to a page that has a TextBox to hold the Title field and a AppBar icon to Save (similar to the ‘New Task’ screenshot in the above link, but with values pre-filled with existing entity with Two-Way binding), the following issue occurs. If I have the TextBox selected and I change the title and hit the save button, it updates the entity in-memory so that the full list now displays the new title. But the new title is not persisted to the DB (it does not auto-detect changes). This is weird, not just because the object in-memory has changed, but also because if I deselect the TextBox and then hit save, it will persist the changes to the DB.

I have seen other questions on SO with some change detection issues, they suggest adding this.Focus() or focusing some other element at the beginning of the save method. This does not help in my case. Unless I tap on screen to deselect the TextBox and hide the keyboard (or press Return key on the keyboard, which I bound to do this.Focus()), it won’t detect the object as changed.

How can I address this? What exactly is stopping EF from detecting the object change when the keyboard is still visible?

  • 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-30T02:44:18+00:00Added an answer on May 30, 2026 at 2:44 am

    Not sure if I follow exactly what you described but I think the problem is that the property you have bound your textbox to does not get updated until the TextChanged is fired on the textbox, and this is done first when you leave the Textbox, basically it will lose Focus if you tap somewhere else.

    There is a simple workaround for this and it behaviors. By making a small behavior you can force the textbox to update the binding on each keystroke – so everything is updated while you type and keyboard is still there.

    Behavior:

    /// <summary>
    /// Update property on every keystroke in a textbox
    /// </summary>
    public class UpdateTextSourceTriggerBehavior : Behavior<TextBox>
    {
        protected override void OnAttached()
        {
            this.AssociatedObject.TextChanged += OnTextBoxTextChanged;
        }
    
        void OnTextBoxTextChanged(object sender, TextChangedEventArgs e)
        {
            var bindingExpression = AssociatedObject.ReadLocalValue(TextBox.TextProperty) as BindingExpression;
            if (bindingExpression != null)
            {
                bindingExpression.UpdateSource();
            }
        }
    
        protected override void OnDetaching()
        {
            this.AssociatedObject.TextChanged -= OnTextBoxTextChanged;
        }
    }
    

    Now just attach this behavior to your textbox like this:

    <TextBox Text="{Binding YourPropertyName, Mode=TwoWay}">
                    <i:Interaction.Behaviors>
                        <UpdateTextSourceTriggerBehavior/>
                    </i:Interaction.Behaviors>
                </TextBox>
    

    This will keep the property on your viewmodel updated all the time, so that when you tap on save directly after typing in the textbox it will save the correct value. Hope it helps!

    Cheers,
    Anders

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to adress the following issue: I have a server side .net application
I’m trying to issue web requests asynchronously. I have my code working fine except
I have the following simple line in d3 but haven't an issue trying to
I have discovered an issue when trying to store a lot of keys using
I have an issue while trying to parse an Xml to Objects using Linq
I have an issue trying to delete using hibernate. When I try to delete
I'm new to XSLT and I have the following issue when trying to use
I have ran into an interesting issue while trying to create a more usable
can anyone help? I have an issue with linq2sql and trying to Attach (update)
The issue I am trying to solve is that I have a folder with

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.