question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WinUI 3 Desktop - Binding does not work

See original GitHub issue

In 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:closed
  • Created 3 years ago
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
Ratcha9commented, Jun 11, 2020

My experience is that legacy bindings do not update the target property, when the the PropertyChanged event is raised, regardless of setting the DataContext property or not.

@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.

1reaction
tomasfabiancommented, Jun 11, 2020

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found