C# 在xamarin android中如何将数据从ViewModel传递到Activity 我试图做的是:将数据从ViewModel传递到Activity
ViewModel.csC# 在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
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