Xamarin.Forms - ContentView - DisplayActionSheet

Xamarin.Forms - ContentView - DisplayActionSheet

我有页面。在我的页面中有项目 - 每个项目都是 grid。在 grid 我有几个 contentviews。其中之一 - 我有按钮。

现在我想尝试显示给用户DisplayActionSheet。 - 但因为它是一个内容视图 - 我不能称之为 -

我也试过 App.Current.MainPage - 但它确实帮了我。

P.S - 还有问题 - 也许你知道做这样的事情的方法: http://www.w3schools.com/bootstrap/tryit.asp?filename=trybs_dropdown-menu&stacked=h 在 xamarin 中?

谢谢

只是一种使用MessagingCenter的方法。

在您的 ContentView 中,当您希望包含页面执行 DisplayActionSheet 时,您可以发布 消息。在 ContentView 中,如果需要,您还可以 订阅 DisplayActionSheet 的结果,方法是让 ContentPage 发布用户选择的结果以及订阅该结果的任何内容消息 ID(您的 ContentView 可能)然后可以对其做出反应。

ContentView基码:

var gridButton = new Button { Text = "This button is in a Content View" };
gridButton.Clicked += delegate
{
    var questions = new List<string> { "My ActionSheet Title", "Cancel", "Delete", "Share" };
    MessagingCenter.Send<object, List<string>>(this, "PhotoMessageQuestion", questions);
};

MessagingCenter.Subscribe<object, string>(this, "PhotoMessageAnswer", (sender, arg) =>
{
    System.Diagnostics.Debug.WriteLine("User choose: {0}", arg);
});

ContentPage基码:

MessagingCenter.Subscribe<object, List<string>>(this, "PhotoMessageQuestion", async (sender, arg) =>
{
    var photoAction = await DisplayActionSheet(arg[0], arg[1], arg[2], arg[3]);
    MessagingCenter.Send<object, string>(this, "PhotoMessageAnswer", photoAction);
});

结果: