将 MvxCommand 与 CommandParameter 绑定一起使用 [英] Using MvxCommand With CommandParameter binding

查看:43
本文介绍了将 MvxCommand 与 CommandParameter 绑定一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 fire MvxCommand with CommandParameter,但面临有以下问题:MyView.axml 包含:

I'm trying using fire MvxCommand with CommandParameter, but faced with following problem: MyView.axml contains:

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button1"
        local:MvxBind="Click MyCommand, CommandParameter=foo" />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button2"
        local:MvxBind="Click MyCommand, CommandParameter=bar" />
</LinearLayout>

MyViewModel.cs:

MyViewModel.cs:

public class MyViewModel : MvxViewModel
{
    public ICommand MyCommand { get; private set; }

    public MyViewModel()
    {                                    // param is null
      MyCommand = new MvxCommand<string>(param =>
      {
          if (param == "foo")               
          {
            // do something
          }
          else if (param == "bar")
          {
            // do something else
          }
      });
    }
}

但是当我检查 param 变量是 null.

But when I check param variable is null.

我做错了什么?

推荐答案

你的代码在我的源代码树的头部对我有用.

Your code is working for me on the Head of my source tree.

但是这个功能只有两周的时间.

But this functionality is only two weeks old.

我的猜测是此功能要么没有包含在您正在使用的版本中,要么存在错误.

My guess is that this feature either didn't make it into the release that you are working with or there was a bug with it.

你能检查一下这个绑定的调试跟踪吗?有资料吗?

Can you check your debug trace for this binding? Is there any information there?

  • 如果跟踪表明 CommandParameter 是一个未知符号,那么我的猜测是您需要自己构建最新的源代码 - 或者等待新版本.
  • 如果跟踪提示其他问题,那么您可以在设置过程中修补问题.
  • If the trace suggests that CommandParameter is an unknown symbol then my guess is that you will need to either build the latest source yourself - or to wait for a new release.
  • If the trace suggests something else then you may be able to patch the problem during setup.

我知道我们修复的一件事是值转换器问题,其中基于 Cirrious.MvvmCross.Binding.dllValueConverter 不仅仅是通过覆盖 Setup.ValueConverterAssemblies 注册此 CommandParameter

One thing I know we did fix was a value converter issue where the Cirrious.MvvmCross.Binding.dll based ValueConverter's weren't being just by overriding Setup.ValueConverterAssemblies to register the ValueConverter required for this CommandParameter

这篇关于将 MvxCommand 与 CommandParameter 绑定一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆