Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在Xamarin中,将数据从一个视图传递到另一个视图的最佳方式是什么?_C#_Xamarin - Fatal编程技术网

C# 在Xamarin中,将数据从一个视图传递到另一个视图的最佳方式是什么?

C# 在Xamarin中,将数据从一个视图传递到另一个视图的最佳方式是什么?,c#,xamarin,C#,Xamarin,在Xamarin中,使用MVVM模式将数据从一个视图传递到另一个视图的最佳方式是什么 即使对象中的数据很大,传入构造函数是否也是最好的选择 我们还可以使用什么样的模式来传递数据?假设您使用的是Xamarin.Forms有很多方法可以做到这一点(取决于您构建应用程序的方式) 如果页面已打开,则可以使用MessagingCenter从一个视图模型或页面发送到另一个视图模型或页面,同时保留架构 发送方 MessagingCenter.Send<MainPage> (this, "Hi");

在Xamarin中,使用MVVM模式将数据从一个视图传递到另一个视图的最佳方式是什么

即使对象中的数据很大,传入构造函数是否也是最好的选择


我们还可以使用什么样的模式来传递数据?

假设您使用的是
Xamarin.Forms
有很多方法可以做到这一点(取决于您构建应用程序的方式)

如果页面已打开,则可以使用MessagingCenter从一个视图模型或页面发送到另一个视图模型或页面,同时保留架构

发送方

MessagingCenter.Send<MainPage> (this, "Hi");
MessagingCenter.Subscribe<MainPage> (this, "Hi", (sender) => {
    // do something whenever the "Hi" message is sent
});
public MyPage(string someText)
{
}
await Navigation.PushAsync(new NavigationPage(new MyPage(<YourTextHere>)));
发送方

MessagingCenter.Send<MainPage> (this, "Hi");
MessagingCenter.Subscribe<MainPage> (this, "Hi", (sender) => {
    // do something whenever the "Hi" message is sent
});
public MyPage(string someText)
{
}
await Navigation.PushAsync(new NavigationPage(new MyPage(<YourTextHere>)));

额外资源


假设您使用的是
Xamarin.Forms
有很多方法可以做到这一点(取决于您构建应用程序的方式)

如果页面已打开,则可以使用MessagingCenter从一个视图模型或页面发送到另一个视图模型或页面,同时保留架构

发送方

MessagingCenter.Send<MainPage> (this, "Hi");
MessagingCenter.Subscribe<MainPage> (this, "Hi", (sender) => {
    // do something whenever the "Hi" message is sent
});
public MyPage(string someText)
{
}
await Navigation.PushAsync(new NavigationPage(new MyPage(<YourTextHere>)));
发送方

MessagingCenter.Send<MainPage> (this, "Hi");
MessagingCenter.Subscribe<MainPage> (this, "Hi", (sender) => {
    // do something whenever the "Hi" message is sent
});
public MyPage(string someText)
{
}
await Navigation.PushAsync(new NavigationPage(new MyPage(<YourTextHere>)));

额外资源