【发布时间】:2021-05-04 14:33:56
【问题描述】:
我的 Xamarin 应用程序上有一个菜单,它是一个包含 3 个消耗性对象的简单圆圈。
我想做的是:
- 将它们与一个矩形组合在一起,使其看起来更像一个弹出菜单。
- 添加扩展菜单项的功能
预期结果:Here
我试图通过将网格放在我的主网格中来将菜单项组合在一起,但没有收到预期的输出..
这是我的 MenuView.xaml 代码:
<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:models="clr-namespace:MenuApp.Models;assembly=MenuApp"
xmlns:MenuApp="clr-namespace:MenuApp;assembly=MenuApp"
x:Class="MenuApp.Views.MenuView">
<ContentView.Content>
<ScrollView>
<StackLayout x:Name="menuLayout" >
<ImageButton Source="{MenuApp:ImageResource MenuApp.Images.circle.png}" BackgroundColor="Transparent" x:Name="MainMenu"
Clicked="TapGestureRecognizer_OnTapped" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"
Margin="10" WidthRequest="50" HeightRequest="50" ></ImageButton>
</StackLayout>
</ScrollView>
</ContentView.Content>
</ContentView>
MenuView.cs 的代码
private void InitializeMenu()
{
LockLandScape();
var children = new List<MenuItem>()
{
new MenuItem { Type = ButtonType.Home},
new MenuItem { Type = ButtonType.Settings},
new MenuItem { Type = ButtonType.Rotate},
}; // get list from Settings.
}
欢迎任何想法!谢谢。
【问题讨论】:
-
Shell 模板可以做你想做的事。你可以直接使用它。检查 MS 文档。 docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/…
-
我不想使用 shell 模板,没有模板可以做到吗? @WendyZang-MSFT
-
我已经在回复中贴出了代码。请检查一下。
标签: javascript visual-studio asp.net-core xamarin menuitem