【问题标题】:Show Action Menu in Xamarin Forms Application在 Xamarin Forms 应用程序中显示操作菜单
【发布时间】:2019-10-15 19:37:08
【问题描述】:

在我的应用程序中,我的屏幕右下角有一个按钮操作,单击该按钮后,应该会出现类似图像中的内容。我不知道如何得到这个,看起来类似于 android 中的上下文菜单。需要帮助!

【问题讨论】:

标签: xamarin xamarin.forms xamarin-studio


【解决方案1】:

正如那里提到的评论,您可以使用Rg.Plugins.Popup 来满足您的要求。我写了一些简单的代码,你可以看看:

Action 菜单页面,它继承PopupPage,我使用listView 来显示选项,您可以自定义viewCell 在右侧添加图像。还要处理ListView_ItemSelected中的点击事件:

public partial class Page1 : PopupPage
{
    public Page1 ()
    {
        InitializeComponent ();

        listView.ItemsSource = new List<string>
        {
            "first",
            "second",
            "third",
            "fourth",
            "fifth",          
        };
    }

    private async void OnClose(object sender, EventArgs e)
    {
        await PopupNavigation.Instance.PopAsync();
    }

    private void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
    {
        //
        var index = (listView.ItemsSource as List<string>).IndexOf(e.SelectedItem as string);

        Console.WriteLine(index);
    }
}

在 Xaml 中:

<StackLayout VerticalOptions="End" HorizontalOptions="FillAndExpand" Padding="20, 20, 20, 20" >
    <Frame CornerRadius="25" Padding="0" Margin="0,0,0,0" BorderColor="Red" HasShadow="False" IsClippedToBounds="True">
        <StackLayout BackgroundColor="White" VerticalOptions="End" >

            <ListView x:Name="listView" HeightRequest="250" RowHeight="50" ItemSelected="ListView_ItemSelected">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <TextCell TextColor="Black" Text="{Binding .}"></TextCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>

        </StackLayout>
    </Frame>

    <Frame CornerRadius="25"  Padding="0" BackgroundColor="White" IsClippedToBounds="True">
        <StackLayout BackgroundColor="White" VerticalOptions="End" HeightRequest="50">

            <Button Text="Close" TextColor="#A9D1DE" Clicked="OnClose"></Button>

        </StackLayout>
    </Frame>

</StackLayout>

要使用此页面:

   await PopupNavigation.Instance.PushAsync(new Page1());

您应该修改详细信息以满足您的要求。比如自定义viewCell,禁用ListView的滚动能力等等。

这是它在 iOS 中的样子:

【讨论】:

    猜你喜欢
    • 2019-01-19
    • 1970-01-01
    • 1970-01-01
    • 2014-01-22
    • 2015-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多