【问题标题】:Custom Animation with MvvmCross Droid使用 MvvmCross Droid 自定义动画
【发布时间】:2013-07-11 15:55:00
【问题描述】:

使用 MvvmCross,如果我想要一个按钮来打开一个新屏幕,我连接命令处理程序并使用 ShowViewModel,如下所示:

        ShowViewModel<InfoViewModel>();

是否可以插入自定义动画,这些动画是非常特定于平台的,并且仍然在核心中使用 ShowViewModel?如果我在一个 Droid 项目中这样做,它看起来像这样:

        OverridePendingTransition(Resource.Animation.push_up_in, Resource.Animation.push_up_out);

所以基本上我想要一种从 Droid 项目中挂钩 MvvmCross Activity 创建的方法。

【问题讨论】:

    标签: xamarin mvvmcross xamarin.droid


    【解决方案1】:

    终于成功了!

    在安装程序中覆盖 CreateViewPresenter()

    public class Setup : MvxAndroidSetup
    {
     ...
     ...
        protected override IMvxAndroidViewPresenter CreateViewPresenter()
        {
            return new CustomPresenter();
        }
    }
    

    并创建了一个 CustomPresenter 类来做动画:

    public class CustomPresenter : MvxAndroidViewPresenter
    {
    
        protected override void Show(Intent intent)
        {
            Activity.StartActivity(intent);
            Activity.OverridePendingTransition(Resource.Animator.slide_in_left, Resource.Animator.slide_out_left);
        }
    }
    

    【讨论】:

      【解决方案2】:

      通过从 UI 中的 MvxActivity 调用命令解决。

              var infoBtn = FindViewById<RelativeLayout>(Resource.Id.infobtn);
              infoBtn.Click += delegate(object sender, EventArgs args)
                  {
                      ((MainMenuViewModel)ViewModel).InfoCommand.Execute(null);
                      OverridePendingTransition(Resource.Animation.push_up_in, Resource.Animation.push_up_out);                 
                  };
      

      【讨论】:

      • 如果您想在“正确”的地方执行此操作,那么最好在自定义演示器中执行此操作 - 请参阅来自slodge.blogspot.co.uk/2013/06/presenter-roundup.html的链接
      • 谢谢!我正在调查这个。
      • 您是否设法在“正确”的地方进行操作?查看@Stuart 提供的链接,但找不到任何相关内容。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多