Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.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 android中如何将数据从ViewModel传递到Activity 我试图做的是:将数据从ViewModel传递到Activity_C#_Xamarin_Xamarin.android_Mvvmcross - Fatal编程技术网

C# 在xamarin android中如何将数据从ViewModel传递到Activity 我试图做的是:将数据从ViewModel传递到Activity

C# 在xamarin android中如何将数据从ViewModel传递到Activity 我试图做的是:将数据从ViewModel传递到Activity,c#,xamarin,xamarin.android,mvvmcross,C#,Xamarin,Xamarin.android,Mvvmcross,ViewModel.cs public event EventHandler RecommendedScents; private void _recommendedScents() { var handler = RecommendedScents; if (handler != null) handler(this, new System.EventArgs()); } 活动.cs publi

ViewModel.cs

    public event EventHandler RecommendedScents;
    private void _recommendedScents()
    {
        var handler = RecommendedScents;
        if (handler != null)
            handler(this, new System.EventArgs());

    }
活动.cs

    public event EventHandler RecommendedScents;
    private void _recommendedScents()
    {
        var handler = RecommendedScents;
        if (handler != null)
            handler(this, new System.EventArgs());

    }
我在视图中注册事件

在此处获取控件:

    private void SetRecommendedScents(object sender, EventArgs e)
    {



    }

您不需要使用这种技巧将数据从ViewModel传递到视图。只需将您的视图声明为
MVX活动

并且在视图中会有一个属性ViewModel

[Activity(ScreenOrientation = ScreenOrientation.Portrait)]
public class MyView : MvxActivity<MyViewModel>
{
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        var myValue = ViewModel.SomeProperty; // here you access your VM
    }
}
[活动(ScreenOrientation=ScreenOrientation.纵向)]
公共类MyView:MVX活动
{
创建时受保护的覆盖无效(捆绑包)
{
base.OnCreate(bundle);
var myValue=ViewModel.SomeProperty;//您可以在这里访问VM
}
}
如果需要将数据从ViewModel发送到View,则需要使用事件聚合器系统,如MvvmCross.Plugin.Messenger