Skip to content
14 changes: 13 additions & 1 deletion src/Controls/src/Core/FlyoutPage/FlyoutPage.Mapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public partial class FlyoutPage
#endif
#if WINDOWS
FlyoutViewHandler.Mapper.ReplaceMapping<IFlyoutView, IFlyoutViewHandler>(nameof(PlatformConfiguration.WindowsSpecific.FlyoutPage.CollapseStyleProperty), MapCollapseStyle);
FlyoutViewHandler.Mapper.ReplaceMapping<IFlyoutView, IFlyoutViewHandler>(nameof(PlatformConfiguration.WindowsSpecific.FlyoutPage.CollapsedPaneWidthProperty), MapCollapsedPaneWidth);
#endif
}

Expand All @@ -39,6 +40,7 @@ internal static void MapPrefersPrefersStatusBarHiddenProperty(IFlyoutViewHandler
internal static void MapCollapseStyle(IFlyoutViewHandler handler, IFlyoutView view)
{
var flyoutLayoutBehavior = (view as FlyoutPage)?.FlyoutLayoutBehavior;

if (view is BindableObject bindable && handler.PlatformView is Microsoft.Maui.Platform.RootNavigationView navigationView && flyoutLayoutBehavior is FlyoutLayoutBehavior.Popover)
{
var collapseStyle = PlatformConfiguration.WindowsSpecific.FlyoutPage.GetCollapseStyle(bindable);
Expand All @@ -56,6 +58,16 @@ internal static void MapCollapseStyle(IFlyoutViewHandler handler, IFlyoutView vi
}
}
}

internal static void MapCollapsedPaneWidth(IFlyoutViewHandler handler, IFlyoutView view)
{
if (view is BindableObject bindable && handler.PlatformView is Microsoft.Maui.Platform.RootNavigationView navigationView)
{
var collapsedPaneWidth = PlatformConfiguration.WindowsSpecific.FlyoutPage.GetCollapsedPaneWidth(bindable);
navigationView.CompactPaneLength = collapsedPaneWidth;
}
}

#endif
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static IPlatformElementConfiguration<Windows, FormsElement> UsePartialCol
/// <summary>Bindable property for attached property <c>CollapsedPaneWidth</c>.</summary>
public static readonly BindableProperty CollapsedPaneWidthProperty =
BindableProperty.CreateAttached("CollapsedPaneWidth", typeof(double),
typeof(FlyoutPage), 48d, validateValue: (bindable, value) => (double)value >= 0);
typeof(FlyoutPage), 48d, validateValue: (bindable, value) => (double)value >= 0, propertyChanged : OnCollapsedPaneWidthChanged);

/// <summary>Gets the width of the collapsed flyout pane on Windows.</summary>
/// <param name="element">The element to get the collapsed pane width from.</param>
Expand All @@ -85,6 +85,14 @@ public static double GetCollapsedPaneWidth(BindableObject element)
return (double)element.GetValue(CollapsedPaneWidthProperty);
}

static void OnCollapsedPaneWidthChanged(BindableObject bindable, object oldValue, object newValue)
{
if (bindable is Microsoft.Maui.Controls.FlyoutPage flyoutPage && flyoutPage.Handler is not null)
{
flyoutPage.Handler.UpdateValue(nameof(CollapsedPaneWidthProperty));
}
}

/// <summary>Sets the width of the collapsed flyout pane on Windows.</summary>
/// <param name="element">The element to set the collapsed pane width on.</param>
/// <param name="collapsedPaneWidth">The collapsed pane width in device-independent units.</param>
Expand Down
76 changes: 76 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue33785.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using Microsoft.Maui.Controls.PlatformConfiguration;
using Microsoft.Maui.Controls.PlatformConfiguration.WindowsSpecific;

namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 33785, "[Windows] FlyoutPage CollapsedPaneWidth Not Working", PlatformAffected.UWP)]
public class Issue33785 : TestFlyoutPage
{
Microsoft.Maui.Controls.Label _label;
protected override void Init()
{
this.On<Microsoft.Maui.Controls.PlatformConfiguration.Windows>().SetCollapseStyle(CollapseStyle.Partial);
this.On<Microsoft.Maui.Controls.PlatformConfiguration.Windows>().CollapsedPaneWidth(50);

// Set the flyout page properties
FlyoutLayoutBehavior = FlyoutLayoutBehavior.Popover;

// Create the flyout content
var flyoutPage = new ContentPage
{
Title = "Master",
BackgroundColor = Colors.Blue
};

var page1Button = new Button
{
Text = "Change",
AutomationId = "FlyoutItem",
HorizontalOptions = LayoutOptions.Start,
VerticalOptions = LayoutOptions.Center
};
page1Button.Clicked += (s, e) =>
{
this.On<Microsoft.Maui.Controls.PlatformConfiguration.Windows>().CollapsedPaneWidth(100);
_label.Text = "CollapsedPaneWidth set to 100";
};

flyoutPage.Content = new VerticalStackLayout
{
Children = { page1Button }
};

// Create the detail content
var detailPage = new ContentPage
{
Title = "Detail",
BackgroundColor = Colors.LightYellow
};

_label = new Microsoft.Maui.Controls.Label
{
Text = "Test for CollapsedPaneWidth",
AutomationId = "CollapsedPaneLabel",
HorizontalOptions = LayoutOptions.Center,
HorizontalTextAlignment = TextAlignment.Center,
};

detailPage.Content = new VerticalStackLayout
{
Children = {
new Microsoft.Maui.Controls.Label
{
Text = "Welcome to .NET MAUI!",
TextColor = Colors.Black,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center
},
_label
}
};

// Set the flyout and detail pages
Flyout = flyoutPage;
Detail = detailPage;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#if WINDOWS //CollapsedPaneWidth is Windows Specific API
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;
public class Issue33785 : _IssuesUITest
{
public Issue33785(TestDevice device) : base(device) { }

public override string Issue => "[Windows] FlyoutPage CollapsedPaneWidth Not Working";
[Test]
[Category(UITestCategories.FlyoutPage)]
public void VerifyFlyoutPageCollapsedPaneWidth()
{
App.WaitForElement("CollapsedPaneLabel");
App.TapFlyoutPageIcon();
App.Tap("FlyoutItem");
App.TapFlyoutPageIcon();
VerifyScreenshot();
}
}
#endif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading