-
Notifications
You must be signed in to change notification settings - Fork 793
Open
0 / 60 of 6 issues completedOpen
0 / 60 of 6 issues completed
Copy link
Labels
Regressionarea-BindingbugSomething isn't workingSomething isn't workingteam-MarkupIssue for the Markup teamIssue for the Markup teamwct
Description
Describe the bug
Apparently it is possible to use x:Bind to bind to a field in code behind outside a data template. Basically, escaping from the data template in use. Not entirely sure whether this is by design or just a lucky quirk of the XAML compiler and codegen (especially since this is not mentioned anywhere in the docs), but it works.
As a code example:
<UserControl
x:Class="MyNamespace.Views.MyUserControl"
xmlns:viewModels="using:MyNamespace.ViewModels"
models="using:MyNamespace.Models">
<UserControl.DataContext>
<viewModels:MyViewModel x:Name="ViewModel"/>
</UserControl.DataContext>
<UserControl.Resources>
<DataTemplate
x:Name="SomeDataTemplate"
x:DataTye="models:SomeModelTyppe">
<!--This works-->
<TextBlock Text="{x:Bind ViewModel.SomeText}"/>
</DataTemplate>
</UserControl.Resources>
<ListView
ItemsSource="{x:Bind ViewModel.MyItems}"
ItemTemplate="{StaticResource SomeDataTemplate}"/>
</UserControl>You can see how the binding is escaping the data template and just targeting a field in code behind.
The problem with this is that it's extremely fragile and inconsistent:
x:Bindto a property outside the data template works fine ✅x:Bindto that same property but with function binding fails to build ❌x:Bindto that same property from a visual state setter crashes at runtime ❌x:Bindto that same property with a converter crashes at runtime ❌
Steps to reproduce the bug
Steps to reproduce the behavior:
- Download this repro
- Open the solution, run the app
Expected behavior
🤷♂️ 🤷♂️ 🤷♂️
Actual behavior
The binding to the outside field (the view model) works just fine
Screenshots
| Windows 10 version | Saw the problem? |
|---|---|
| Insider Build (xxxxx) | |
| November 2019 Update (18363) | Yes |
| May 2019 Update (18362) | Yes |
| October 2018 Update (17763) | |
| April 2018 Update (17134) | |
| Fall Creators Update (16299) | |
| Creators Update (15063) |
| Device form factor | Saw the problem? |
|---|---|
| Desktop | Yes |
| Mobile | |
| Xbox | |
| Surface Hub | |
| IoT |
cc. @MikeHillberg
matthew4850, michael-hawker, jamesmcroft, Felix-Dev, mrjfalk and 20 more
Sub-issues
Metadata
Metadata
Assignees
Labels
Regressionarea-BindingbugSomething isn't workingSomething isn't workingteam-MarkupIssue for the Markup teamIssue for the Markup teamwct
Type
Projects
Status
Ready
