【问题标题】:Change Hamburger Menu Icon in .NET MAUI app在 .NET MAUI 应用程序中更改汉堡包菜单图标
【发布时间】:2023-02-10 16:16:26
【问题描述】:

如何更改 .NET MAUI 应用程序中的汉堡包菜单图标?

我已经更新了所有图标的样式,并且我想将汉堡包菜单图标更改为自定义的 PNG

我在 Styles.xaml 中尝试了以下内容,但这似乎不是要编辑的正确属性。

<Style TargetType="FlyoutPage">
    <Setter Property="IconImageSource" Value="custom_menu_icon.png" />
</Style>

【问题讨论】:

  • 我正在尝试创建汉堡菜单但没有成功。例如,你能告诉我你的代码吗?
  • 你在你的 MAUI 应用程序中使用 AppShell 吗?如果是这样,您是否在AppShell.xaml 中定义了FlyoutItem
  • 是的,我正在使用 AppShell。我尝试了一切,但从未得到任何结果(可见结果)。

标签: maui


【解决方案1】:

FlyoutPage 的解决方案

FlyoutPage 的 Flyout 是 ContentPage 类型的,因此图标应该设置在那里:

<ContentPage
    IconImageSource="custom_menu_icon.png" />
</ContentPage>

您也可以在Styles.xaml 中定义它并将样式分配给页面:

<Style TargetType="ContentPage" x:Key="FlyoutStyle">
    <Setter Property="IconImageSource" Value="custom_menu_icon.png" />
</Style>
<ContentPage
    Style="{StaticResource FlyoutStyle}" />
</ContentPage>

另见:https://learn.microsoft.com/dotnet/maui/user-interface/pages/flyoutpage?view=net-maui-7.0#create-a-flyoutpage

这假定您使用的是 FlyoutPage 而不是 Shell

壳牌解决方案

如果您使用的是 Shell,则可以按如下方式定义样式:

<Style TargetType="Shell" ApplyToDerivedTypes="True">
    <!-- skipping existing setters here -->
    <Setter Property="Shell.FlyoutIcon" Value="custom_menu_icon.png" />
</Style>

查看更多:https://learn.microsoft.com/dotnet/maui/fundamentals/shell/flyout?view=net-maui-7.0#flyout-icon

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-10
    • 2018-03-16
    • 2021-03-17
    • 2018-08-10
    相关资源
    最近更新 更多