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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:52:54+00:00 2026-06-06T11:52:54+00:00

is there a way to update a binding before or when a command is

  • 0

is there a way to update a binding before or when a command is triggered? I have some text fields I can edit and save using a command, accessible via a keyboard shortcut. As the binding is usually only updated when the text field loses focus, the last change is not kept when pressing the key to save the data. Instead I have to tab out of the text field first to make it update and then save it.

Is there a way to force the update in an elegant way? I am using MVVM (but not any MVVM framework), so I’d like to keep UI specific things out of the command code. Also I don’t really want to change the binding to update on every change, it’s fine to have it update only when the focus is lost.

  • 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-06-06T11:52:55+00:00Added an answer on June 6, 2026 at 11:52 am

    I have solved this now by explicitely setting the focus to some other element before asking for the values. This obviously makes the element that currently has the focus lose it and update the binding.

    To set the focus, I have written an attached property, inspired by answers on other questions. Also, together with my other question I made this somewhat automated.

    So to use it, I basically attach my property to an element, in this case a tab control:

    <TabControl c:Util.ShouldFocus="{Binding ShouldClearFocus}">
    

    In my view model, I have a simple boolean property ShouldClearFocus that is a standard property raising a PropertyChangedEvent, so data binding works. Then I simply set ShouldClearFocus to true when I want to reset the focus. The attached property automatically sets the focus and resets the property value again. That way I can keep setting ShouldClearFocus without having to set it to false in between.

    The attached property is a standard implementation with this as its change handler:

    public static void ShouldFocusChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
    {
        if (!(bool)e.NewValue || !(obj is FrameworkElement))
            return;
    
        FrameworkElement element = (FrameworkElement)obj;
        if (element.Focusable)
            element.Focus();
    
        // reset value
        BindingExpression bindingExpression = BindingOperations.GetBindingExpression(obj, ShouldFocusProperty);
        if (bindingExpression != null)
        {
            PropertyInfo property = bindingExpression.DataItem.GetType().GetProperty(bindingExpression.ParentBinding.Path.Path);
            if (property != null)
                property.SetValue(bindingExpression.DataItem, false, null);
        }
        else
            SetShouldFocus(obj, false);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to update nested documents by id or some other field?
I there a way to update a row without mentioning fields name ? I
Within a repeater control, is there a way of de-binding certain items before the
Is there a way to edit the Request.Form before the action method binds to
I have a text field that I'm binding the paste event to using JQuery.
Question : is there a way to do automatic command object binding with request.JSON
Is there any way to update my beta testing application on windows phone marketplace?
Is there a way to update only the parent UpdatePanel without updating the child
Is there any way to update a table layout after it has been created?
Is there a way to update only Hour part in a DateTime field?? If

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.