我有一个ListView
,并且有CustomViewCell
。 CustomViewCell
的按钮很少。
按钮: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/