dotnet / maui-samples

Samples for .NET Multi-Platform App UI (.NET MAUI)
https://dot.net/maui
MIT License
3.08k stars 1.27k forks source link

FlyoutPageSample OnSelectionChanged Bug #219

Open DeepWorksStudios opened 2 years ago

DeepWorksStudios commented 2 years ago

Description

If you selected a flyout it breaks with the error

System.InvalidOperationException: 'Can't change IsPresented when setting Default'

Exception Details as log

image

Steps to Reproduce

  1. Pull current maui smaple

  2. Start Project FlyoutPageSample

  3. Target on Windows

  4. Start Application

  5. Select any Flyout Item

Version with bug

6.0.400 (current)

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

All Windows Versions

Did you find any workaround?

No

Relevant log output

exceptionBreak.txt

linkaiyu commented 2 years ago

for now I just comment out the line in order to run the app, but it's not clear to me what impact it has.

jamesmontemagno commented 2 years ago

Looks like functionality is correct as far as exception is concerned, https://github.com/dotnet/maui/blob/7efa74c205e40c9e849294eb47e6566139f80404/src/Controls/src/Core/FlyoutPage.cs#L269

Should update the demo to not have that option based on the scenario.

However, honestly we should not recommend flyoutpage and Shell should be used in all cases.

linkaiyu commented 2 years ago

Thanks James for the guidance. I've played with the shellflyout sample and it does make more sense.

molesmoke commented 2 years ago

Looks like the documentation might also be incorrect, unless the current behaviour is a bug: https://docs.microsoft.com/en-us/dotnet/maui/user-interface/pages/flyoutpage

DeepWorksStudios commented 2 years ago

I'm honest, it's really confusing since this is an official template with no changes and if I understood correctly, it shouldn't be used? Then the question is why even provide such a template in this case

CodeSetting commented 2 years ago

I wish I'd noticed this thread earlier. I dug into this a bit more and commented in the related #229. The problem is that IsPresented = false appears incompatible with a split layout (FlyoutLayoutBehavior.Split and SplitXXX).

On the Windows platform, where FlyoutLayoutBehavior.Default is implemented as FlyoutLayoutBehavior.Split, the exception occurs.

On the Android platform, where FlyoutLayoutBehavior.Default is implemented as FlyoutLayoutBehavior.Popover, everything seems to work fine.

My workaround was to simply add FlyoutLayoutBheavior = "Popover" to the FlyoutPage in AppFlyout.xaml. Then, things appear to work correctly on both platforms.

CodeSetting commented 2 years ago

I'm still learning MAUI, but I think I finally understand the full dimension of this problem.

The line IsPresented = false is primarily intended to dismiss a popover dialog. When using a split layout, instead of a popover layout, dismissing it does not make sense (and is not supported)...so it throws an InvalidOperationException.

The correct way to fix this is probably to change the following line in AppFlyout.xaml.cs:

IsPresented = false;

To only dismiss popover layouts, as follows:

if (!((IFlyoutPageController)this).ShouldShowSplitMode)
  IsPresented = false;
DeepWorksStudios commented 1 year ago

The problem still exists today, and worse, the latest expansion makes it unbuildable unless removed the code of the FlyoutPage Sample.csproj

<ItemGroup>
        <KnownRuntimePack Update="@(KnownRuntimePack)">
            <LatestRuntimeFrameworkVersion Condition="'%(TargetFramework)' == 'net7.0'">6.0.4</LatestRuntimeFrameworkVersion>
        </KnownRuntimePack>
        <KnownFrameworkReference Update="@(KnownFrameworkReference)">
            <TargetingPackVersion Condition="'%(TargetFramework)' == 'net7.0'">6.0.4</TargetingPackVersion>
            <LatestRuntimeFrameworkVersion Condition="'%(TargetFramework)' == 'net7.0'">6.0.4</LatestRuntimeFrameworkVersion>
        </KnownFrameworkReference>
    </ItemGroup>
DeepWorksStudios commented 8 months ago

Any updates?

DeepWorksStudios commented 2 weeks ago

will the demos be updated correctly some day? if yes whene would that be