【问题标题】:Xamarin.Forms - ContentView - DisplayActionSheetXamarin.Forms - ContentView - DisplayActionSheet
【发布时间】:2016-08-26 02:40:01
【问题描述】:

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

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

我也试过App.Current.MainPage - 但它对我没有帮助。

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

谢谢

【问题讨论】:

  • 您需要服务或事件或消息来通知所有者页面以显示操作表
  • 你能给个例子的链接吗?

标签: xamarin xamarin.ios xamarin.android xamarin.forms


【解决方案1】:

只是使用MessagingCenter的一种方法。

当您希望包含页面执行DisplayActionSheet 时,您可以在您的 ContentView 中发布一条消息。在 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);
});

结果:

【讨论】:

  • 哇——看起来不错。我会检查它并在此处更新结果。谢谢你!!!!
  • 好的 - 我刚刚检查过这种方式 - 效果很好。谢谢!话题可以关闭)
猜你喜欢
  • 2017-03-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-24
  • 2021-02-09
  • 1970-01-01
  • 2019-09-30
相关资源
最近更新 更多