locked
TwoWay Binding Fails Under Some Circumstances RRS feed

  • Question

  • I have encountered a situation where two-way binding fails.  Consider the following control:

    <TextBox Text="{Binding Name, Mode=TwoWay}" />

    This XAML associated with this control is contained in an assembly that is dynamically loaded.  The XAML class is then instantiated and added to a content section in a master XAML page.  This master XAML contains a header, footer, breadcrumbs, and the content section.  Before new content is added to the master page, I invoke a routine to determine if any changes were made to the current content page.  If so, I prompt the user and give him/her the opportunity to save the changes.  Pretty common stuff.

    If the user changes the contents of the above TextBox, does NOT tab out of the control, and clicks a bread crumb to navigate to a previous content, the underlying item source does NOT get updated with the TextBox changes, and thus the code that detects changes does not see any changes.  This results in the changes being lost.

    However, if the user tabs after changing the contents of the TextBox, the underlying item source is updated.

    Also, if the user clicks on a "Return" button that is a part on the content page, the underlying item source is updated.

    The issue only arises when the breadcrumb, which is a part of the master page, is clicked.

    Note that the breadcrumb is just a templated Button.

    Thanks for looking into this issue.  Please let me know if there is anything I can do to assist in this investigation.

    W James

    P.S. Maybe it would be useful to provide a method to force resync the control data with the underlying item source.

     

    Tuesday, April 22, 2008 10:10 AM

Answers

  • Hello, this is by design. Two way data binding will only update the data source when the TextBox loses focus. So you'll have to manually set focus to another Control in the Button's Click event handler.

    Thursday, April 24, 2008 3:01 AM

All replies

  • Hello, this is by design. Two way data binding will only update the data source when the TextBox loses focus. So you'll have to manually set focus to another Control in the Button's Click event handler.

    Thursday, April 24, 2008 3:01 AM
  • I guess I wasn't clear in my original post.  By clicking the breadcrumb (templated button), you ARE changing focus.  The contents of the TextBox are still NOT applied to the underlying data source.

     

    Monday, May 5, 2008 2:26 PM