c# - 如何以Xamarin形式从CustomViewCell调用任何Navigation.PushPopupAsync?

标签 c# listview mvvm xamarin.forms

我有一个ListView,并且有CustomViewCellCustomViewCell的按钮很少。

按钮:ShowProfile:此按钮弹出另一页。问题是我不知道如何在Navigation.PushPopupAsync中使用CustomViewCell。我还需要在其中传递当前的CustomViewCell详细信息。

这是我如何在另一个页面中使用Navigation.PushPopupAsync的示例,该页面工作正常,但在CustomViewCell情况下不起作用。

Navigation.PushPopupAsync(new UserProfilePage(new ExtendedProfile(_viewModel.Profile)));

但是以上代码在CustomViewCell中不起作用。
public partial class ProfileListItemViewCell : CustomViewCell
{
    public ProfileListItemViewCell()
    {
        InitializeComponent();
    }

    protected override void OnBindingContextChanged ()
    {
        base.OnBindingContextChanged ();
    }
    private void MenuItemProfile_Clicked(object sender, System.EventArgs e)
    {
        //not working
        Navigation.PushPopupAsync(new UserProfilePage(new ExtendedProfile(_viewModel.Profile)));
    }
}

最佳答案

这看起来像MessagingCenter的工作

Xamarin.Forms MessagingCenter enables view models and other components to communicate with without having to know anything about each other besides a simple Message contract.



在页面构造器中
MessagingCenter.Subscribe<SomeObject> (this, "MyAwesomeShowWindowMessage", 
(someObject) =>
{
     Navigation.PushPopupAsync(new UserProfilePage(new ExtendedProfile(someObject)));
});

来自您的单元格
 MessagingCenter.Send(SomeObject, "MyAwesomeShowWindowMessage");

当您退出听力页面时,别忘了退订
 MessagingCenter.Unsubscribe<SomeObject> (this, "MyAwesomeShowWindowMessage"));

其他示例

How to use Xamarin.Forms Messaging Center

关于c# - 如何以Xamarin形式从CustomViewCell调用任何Navigation.PushPopupAsync?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48943453/

相关文章:

c# - 使用 SendKeys.sendwait() 发送 "spacebar key"

c#.net 使用向导控件从动态框保持控件状态

java - 即使初始化后列表仍为空

wpf - 使用相同的 DataContext 设置 DataGrid 和 ContextMenu

c# - 从 ViewModel 中选择 TabControl 中的 TabItem

c# - IIS 和 asp.net appcmd

c# - 我们可以更改 PropertyGrid 中单个属性的文本/背景颜色吗

android - 按下 ListView 项时以动画开始 Activity

android - 如何实现两级 DrawerLayout

android - 如何对扩展 AndroidViewModel 的 ViewModel 进行单元测试。构造函数中的应用程序有问题