-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Description
I am struggling with moving from Binding to x:Bind. The discussion about how you need to define a viewmodel in your control's code is way too vague. Specifically, it fails to address how to handle the situation where a control is embedded within another control and its DataContext is therefore set at runtime.
In my control code-behind I've declared this:
private ILocation ViewModel { get; set; } = new Location();
private void LocationControl_DataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args)
{
if( args.NewValue is not ILocation viewModel )
return;
ViewModel = viewModel;
}
The event handler gets called multiple times with "null" values for NewValue. It then gets called with a valid ILocation
value, updates the property ViewModel
... and the UI proudly displays absolutely nothing (i.e., the default values from new Location()
, which is of course useless).
I'm not sure why this is happening. But I think you ought to expand the discussion to do a better job explaining how to get this stuff to work.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: 6dd64d43-7b7b-abed-ff27-fafa2b82df0f
- Version Independent ID: 6c349724-5273-3463-7d7e-b685a89f093f
- Content: xBind markup extension - UWP applications
- Content Source: windows-apps-src/xaml-platform/x-bind-markup-extension.md
- Product: uwp
- Technology: platform
- GitHub Login: @jwmsft
- Microsoft Alias: jimwalk
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
Add FAQ about Live Unit Test dependency on PrjFlt (#3716)