Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/328.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.Forms格式将数据从特定于平台的页面传递到PCL_C#_Xamarin.forms - Fatal编程技术网

C# 以Xamarin.Forms格式将数据从特定于平台的页面传递到PCL

C# 以Xamarin.Forms格式将数据从特定于平台的页面传递到PCL,c#,xamarin.forms,C#,Xamarin.forms,我已经使用PageRenderer创建了一个特定于平台的页面,我需要在单击按钮时从该页面传回数据 我已经研究过使用DependencyService,但我能找到的只是从PCL调用平台项目中的一个方法,我需要做相反的事情,这可能吗? 或者我最好考虑使用传统的事件处理程序,这是Xamarin中的首选方法,还是在Xamarim.Forms中有更好的处理方法 需要传回的数据是一个对象 public class CallAcknowledged { public string CustomerNa

我已经使用PageRenderer创建了一个特定于平台的页面,我需要在单击按钮时从该页面传回数据

我已经研究过使用DependencyService,但我能找到的只是从PCL调用平台项目中的一个方法,我需要做相反的事情,这可能吗? 或者我最好考虑使用传统的事件处理程序,这是Xamarin中的首选方法,还是在Xamarim.Forms中有更好的处理方法

需要传回的数据是一个对象

public class CallAcknowledged
{
    public string CustomerName { get; set; }
    public DateTime CallAcknowledged { get; set; }
    public byte[] Signature { get; set; }
}

我在Xamarin论坛的@AlessandroCaliaro上找到了答案

我需要使用PCLProjectName.App作为消息的来源,它的工作原理是一个梦想

寄件人

MessagingCenter.Send<MyMobileApp.App, string>((MyMobileApp.App)Xamarin.Forms.Application.Current, "Acknowledged", fullNameValue);
MessagingCenter.Send((MyMobileApp.App)Xamarin.Forms.Application.Current,“已确认”,fullNameValue);
订户

MessagingCenter.Subscribe<MyMobileApp.App, string>((App)Application.Current, "Acknowledged", (sender, arg) =>
        {
            Debug.WriteLine("Full Name : " + arg);
        });
MessagingCenter.Subscribe((App)Application.Current,“已确认”,(发件人,arg)=>
{
Debug.WriteLine(“全名:+arg”);
});

感谢@MarkusMichel为我指明了正确的方向

我在Xamarin论坛上的@AlessandroCaliaro的帖子中找到了答案

我需要使用PCLProjectName.App作为消息的来源,它的工作原理是一个梦想

寄件人

MessagingCenter.Send<MyMobileApp.App, string>((MyMobileApp.App)Xamarin.Forms.Application.Current, "Acknowledged", fullNameValue);
MessagingCenter.Send((MyMobileApp.App)Xamarin.Forms.Application.Current,“已确认”,fullNameValue);
订户

MessagingCenter.Subscribe<MyMobileApp.App, string>((App)Application.Current, "Acknowledged", (sender, arg) =>
        {
            Debug.WriteLine("Full Name : " + arg);
        });
MessagingCenter.Subscribe((App)Application.Current,“已确认”,(发件人,arg)=>
{
Debug.WriteLine(“全名:+arg”);
});

感谢@MarkusMichel为我指明了正确的方向

您可以在
App.xaml.cs
class
public static List Mylist中声明公共var而不是在android项目中访问它
var data=App.Mylist
您只需使用
Element
object调用
CustomPage
上的方法,还有消息中心:@MarkusMichel,谢谢您指向消息中心的指针。我可以在同一个项目中发送广告订阅消息,但如果我订阅(在PCL项目中)从UWP项目发送的消息,则不会发生任何事情。有什么我遗漏的吗?非常感谢您的帮助。您可以发布您用于订阅和发送信息的代码吗?也许在一个新问题中,并链接到这里。在大多数情况下,当相应的类设置不正确或不同时,消息中心无法工作。您可以在
App.xaml.cs
class
public static List Mylist中声明public var而不是在android项目中访问它
var data=App.Mylist
您只需使用
Element
object调用
CustomPage
上的方法,还有消息中心:@MarkusMichel,谢谢您指向消息中心的指针。我可以在同一个项目中发送广告订阅消息,但如果我订阅(在PCL项目中)从UWP项目发送的消息,则不会发生任何事情。有什么我遗漏的吗?非常感谢您的帮助。您可以发布您用于订阅和发送信息的代码吗?也许在一个新问题中,并链接到这里。在大多数情况下,当相应的类设置不正确或不同的类时,消息中心不工作。