WinUI 3 Desktop - Binding does not work
See original GitHub issueIn WinUI 3 Preview 1 Desktop - Binding markup extensions are not working correctly in some cases (see comments in XAML). Mode OneWay should be implicit, and all bellow mentioned bindings should work properly.
Steps to reproduce the bug
<StackPanel>
<!-- MyTextBox1 x:Bindng works. Text is updated from VM -->
<TextBox x:Name="MyTextBox1" Text="{x:Bind ViewModel.NewProductName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<!-- MyTextBox2 Binding does not work. Text is not updated from VM -->
<TextBox x:Name="MyTextBox2" Text="{Binding ViewModel.NewProductName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<!-- Command x:Bind works -->
<Button Command="{x:Bind ViewModel.AddNew}" Content="Add (works)" />
<!-- Command Binding does not work -->
<Button Command="{Binding ViewModel.AddNew, Mode=OneWay}" Content="Add (does not work)" />
<!-- Command Binding on nested property does not work -->
<Button Padding="5"
Command="{Binding ViewModel.ListViewModel.ClearFilter, Mode=OneWay}"
Content="Reset" />
<!-- Command x:Bind on nested property does not work without Mode -->
<Button Command="{x:Bind ViewModel.ListViewModel.ClearFilter}" Content="xBindWithoutMode" />
<!-- Command x:Bind on nested property works with explicit Mode OneWay. -->
<Button Command="{x:Bind ViewModel.ListViewModel.ClearFilter, Mode=OneWay}" Content="xBindWithOneWayMode" />
</StackPanel>
public sealed partial class ProductsView : UserControl
{
public ProductsView()
{
this.InitializeComponent();
var productsEntityChangesViewModel = App.Kernel.Get<ProductsEntityChangesViewModel>();
ViewModel = productsEntityChangesViewModel;
}
public static readonly DependencyProperty ViewModelProperty = DependencyProperty.Register(nameof(ViewModel), typeof(ProductsEntityChangesViewModel), typeof(ProductsView), new PropertyMetadata(null));
public ProductsEntityChangesViewModel ViewModel
{
get { return GetValue(ViewModelProperty) as ProductsEntityChangesViewModel; }
set { SetValue(ViewModelProperty, value); }
}
}
NuGet package version: [Microsoft.WinUI 3.0.0-preview1.200515.3]
Device form factor | Saw the problem? |
---|---|
Desktop | Yes |
Mobile | |
Xbox | |
Surface Hub | |
IoT |
Issue Analytics
- State:
- Created 3 years ago
- Comments:14 (4 by maintainers)
Top Results From Across the Web
WinUI 3 Desktop XAML Databinding - WinRT originate error
The problem persists with "WinUI 3 in Desktop" projects. The initial data binding works and the button content L"Atticus" is read from the ......
Read more >WinUI 3 (0.8.1), C++/WinRT (2.0.210714.1), Desktop
It creates the bindings in code behind in a PropertyChangedCallback of the helper property. But the binding doesn't work, why? Best regards
Read more >A Dialog Service for WinUI 3 | XAML Brewer, by Diederik Krols
It's not a bug -it's what the binding engine does- but it smells like a bug, so people logged issues in WinUI and...
Read more >Uwp Textbox
Windows UI Library ( WinUI ) 3 is a native user experience (UX) framework a user to more easily ... UWP TextBox not...
Read more >WinUI 3.0 Misconceptions - Nick's .NET Travels
This causes issues if you are using any third party libraries that don't have a WinUI3 version available, as the UWP controls will...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@StephenLPeters {Binding} still doesn’t work for me. The initial value is correct, but it does not update. You may examine https://github.com/Ratcha9/winui_inpc.
@StephenLPeters I think that the “UWP” x:Bind works correctly in case that OneTime is the default mode (chosen for performance reasons). I didn’t have experience with x:Bind. We all should realize that we are coming from different target frameworks. I’m a big fan of unification… so I’m super excited…
I still think that the “classical” Bindings are not working correcly.