Home Dashboard Directory Help
Search

2-way binding lost when control datacontext changes (Windows Store XAML) by LMKz


Status: 

Active


2
0
Sign in
to vote
Type: Bug
ID: 785617
Opened: 4/25/2013 12:50:30 PM
Access Restriction: Public
1
Workaround(s)
view
1
User(s) can reproduce this bug

Description

As per http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/adc578c5-1653-42b9-861e-3855d8232e6f/

I have a Listview with a bunch of items. Selecting an item in the listview shows a "details" grid with some textboxes so that properties of the Listview->SelectedItem can be edited, via 2 way data binding.
The details grid has its DataContext set to {Binding SelectedItem, ElementName=ListView1} or similar, haven't got it in front of me at present. Basically bound to the selected item of the listview. All was well and good, until I found a serious "gotcha" with this scenario...
If you edit a textbox, and lose focus by selecting a different listview item, the textbox changes will be lost (never propagated back to the object Property). I presume that in the order of events, the listview SelectedItem is changing, which causes the Grid's datacontext to change, and the 2way databinding push back is being lost.
I have a complex workaround in that I put a SelectedItem property into my VM, and in its Set method, raise PropertyChanged via dispatcher.RunAsync so that the UI thread runs to completion before rebinding the grid, which works.

See above forum post for repro code. This works correctly in WPF.
Details
Sign in to post a comment.
Posted by Microsoft on 5/14/2013 at 3:17 AM
Thank you for your bug submission. The issue you reported appears to be on a released Windows Product. If this issue is severe, causing critical business situations or blocking your product development or deployment, please go to http://support.microsoft.com or call 1-800-MICROSOFT for assistance. For Microsoft premier customers, please contact your administrator, your Technical Account Manager, or your Microsoft premier account representative.

To post a question or receive community support for developing Windows Store apps, consider posting your question or concern on the Windows Store apps forum. http://social.msdn.microsoft.com/Forums/en-US/category/windowsapps
Posted by Microsoft on 4/25/2013 at 11:49 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Microsoft on 4/25/2013 at 3:51 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
Posted by LMKz on 4/25/2013 at 12:55 PM
Put a SelectedItem property into the VM, and in its Set method, raise PropertyChanged via dispatcher.RunAsync so that the UI thread runs to completion before rebinding the grid.