Skip to content

[Regression] 10.0.50: Compiled Bindings (TypedBinding) does not resubscribe to intermediary values #34428

@lucastitus

Description

@lucastitus

Description

Release 10.0.50 introduces performance improvements to TypedBindings (#33656), however this introduces a bug where it does not resubscribe to intermediate INPC objects when changed (acc2476#diff-bee8ab0ca9d7b2fdc63c4a340be85c32c8fc33bd437e1e331a93dd84c77d19f3R335)

This was fixed by @StephaneDelcroix on a separate branch, however it did not make it to release
5d6e5a2

Steps to Reproduce

Repro.xaml:

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:Pages"
             x:Class="Pages.Repro"
             x:DataType="local:Repro" SafeAreaEdges="All">
   <VerticalStackLayout Spacing="10">
       <Label Text="{Binding ViewModel.Text}"/>
       <Button Text="Change View Model" Command="{Binding ChangeViewModelCommand }"/>
       <Button Text="Change Nested" Command="{Binding ChangeNestedCommand }"/>
   </VerticalStackLayout>
</ContentPage>

Repo.xaml.cs:

using System.ComponentModel;
using System.Runtime.CompilerServices;
using CommunityToolkit.Mvvm.Input;

namespace Pages;

public class ReproViewModel : INotifyPropertyChanged
{
    public string Text
    {
        get;
        set 
        {
            field = value;
            OnPropertyChanged();
        }
    }
    
    public event PropertyChangedEventHandler? PropertyChanged;

    protected void OnPropertyChanged([CallerMemberName] string? propertyName = null)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
}

public partial class Repro : ContentPage
{
    public ReproViewModel ViewModel
    {
        get;
        set
        {
            field = value;
            OnPropertyChanged();
        }
    }

    public Repro()
    {
        ViewModel = new ReproViewModel 
        { 
            Text = DateTime.Now.ToString()
        };
        
        BindingContext = this;
        
        InitializeComponent();
    }

    [RelayCommand]
    public void ChangeViewModel()
    {
        ViewModel = new ReproViewModel 
        { 
            Text = DateTime.Now.ToString()
        };
    }
    
    [RelayCommand]
    public void ChangeNested()
    {
        ViewModel.Text = DateTime.Now.ToString();
    }
}

Clicking "Change View Model" then "Change Nested" should still update the label text. This works in versions prior to 10.0.50.

Link to public reproduction project repository

No response

Version with bug

10.0.50

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

10.0.40

Affected platforms

macOS, iOS, Android, Windows

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

Metadata

Metadata

Labels

i/regressionThis issue described a confirmed regression on a currently supported versionp/0Current heighest priority issues that we are targeting for a release.platform/androidplatform/iosplatform/windowsregressed-in-10.0.50s/triagedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't working

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions