dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.14k stars 1.74k forks source link

Toggled Command is always called 1 more time when a new window is opened #24925

Open FullDevStudio opened 4 weeks ago

FullDevStudio commented 4 weeks ago

Description

I have the following problem,

If I keep navigating back and forth or open a new window, the toggle command is called for both windows, i.e. the binding remains active regardless of whether I navigate back or close the window.

Steps to Reproduce

  1. start the application under Windows
  2. click on the “Open window” button
  3. click on the “Toggle” button in the new window
  4. in the console you can see that “Toggled to True” is only called once.
  5. close the window
  6. repeat the steps from 2 to 3 and you will see that it is called twice next time, 3 times etc.

Link to public reproduction project repository

https://github.com/FullDevStudio/MauiApp1.git

Version with bug

8.0.90 SR9

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Windows, I was not able test on other platforms

Affected platform versions

net8.0-windows10.0.19041.0

Did you find any workaround?

I know it's because of the “TestData” class, because this class only has one instance. If the behavior is intentional, which I can't imagine since a new window is always created and the old bindings should be lost, then it would be very nice to know how to work around this and still use the same “TestData” class.

the following code fixes the following behavior

       testPage.Disappearing += (sender, args) =>

            {                 testPage.BindingContext = null;             };

Relevant log output

No response

Zhanglirong-Winnie commented 3 weeks ago

This issue has been verified using Visual Studio 17.12.0 Preview 2.0(8.0.90 & 8.0.82). Can repro this issue on Windows platform. image