FlyoutPage.IsPresented behaves different to Xamarin 5
- Dominant language
- C#
- Stars
- 23.3k
- Forks
- 2k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 290
Description
### Description
The [documentation](https://docs.microsoft.com/en-us/dotnet/maui/user-interface/pages/flyoutpage) shows that `IsPresented` must be set to `false` so that the flyout closes on phones:
```xml
void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
var item = e.CurrentSelection.FirstOrDefault() as FlyoutPageItem;
if (item != null)
{
Detail = new NavigationPage((Page)Activator.CreateInstance(item.TargetType));
IsPresented = false;
}
}
```
But this code throws an exception on the Windows platform:
https://github.com/dotnet/maui/blob/65104a2163505138e3b9f2cc798a2e9c4f577566/src/Controls/src/Core/FlyoutPage.cs#L286-L289
Please, update the documentation. See workaround.
**Xamarin**: The behavior changed since Xamarin 5. In Xamarin I have used:
https://github.com/jbe2277/waf/blob/acbf97f70736203b47e5e99d399d691d6121fb0f/src/NewsReader/NewsReader.Presentation/Views/ShellView.xaml.cs#L64
This doesn't work correct anymore. The exception is raised on the Windows platform.
Maybe related: https://github.com/dotnet/maui/issues/9801
### Steps to Reproduce
Clone this repo:
https://github.com/jbe2277/waf/tree/b42f0f1a26287dce428f3c34a2c90b4a7d2aeab7
### Link to public reproduction project repository
https://github.com/jbe2277/waf/tree/b42f0f1a26287dce428f3c34a2c90b4a7d2aeab7
### Version with bug
6.0.486 (current)
### Last version that worked well
Unknown/Other
### Affected platforms
Windows
### Affected platform versions
net6.0-windows10.0.19041.0
### Did you find any workaround?
This commit solved the issue:
https://github.com/jbe2277/waf/commit/69803cef490970a344c370616021464f59ae201d
The important part is:
```C#
if (!((IFlyoutPageController)this).ShouldShowSplitMode) IsPresented = false;
```
I believe this API has some flaws:
1. It's necessary to cast `this` so that `ShouldShowSplitMode` can be accessed. However, this is a main use case and so it should be accessible directly via `FlyoutPage`.
2. The `CanChangeIsPresented` property which I used first for the check doesn't work as expected. Although the property returned `true`, setting of `IsPresented = false` resulted in the exception.
### Relevant log output
_No response_
Contributor guide
Research direction
Start with the FlyoutPage documentation linked in the issue and compare its IsPresented example with the Windows behavior described in src/Controls/src/Core/FlyoutPage.cs at lines 286-289. Review the linked workaround commit and reproduction project, then update the documentation to explain the Windows limitation and workaround; the documentation should no longer recommend code that throws the reported exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- documentation, frontend, operating-systems
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100