MvxTabsFragment无法创建目标绑定以绑定命令 [英] MvxTabsFragment Failed to create target binding for binding Command for

查看:56
本文介绍了MvxTabsFragment无法创建目标绑定以绑定命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建MvxTabsFragmentActivity并将片段上的按钮绑定到命令.我遇到的问题是以下错误.

I'm trying to create an MvxTabsFragmentActivity and bind a button on a fragment to a command. The problem I'm getting is the following error.

MvxBind:Warning:  7.94 Failed to create target binding for binding Command for SignInCommand
[0:] MvxBind:Warning:  7.94 Failed to create target binding for binding Command for SignInCommand
04-01 00:40:53.062 I/mono-stdout( 5079): MvxBind:Warning:  7.94 Failed to create target binding for binding Command for SignInCommand
04-01 00:40:53.082 D/Mono    ( 5079): Remapped public key token of retargetable assembly System from 7cec85d7bea7798e to b77a5c561934e089
04-01 00:40:53.082 D/Mono    ( 5079): The request to load the retargetable assembly System v2.0.5.0 was remapped to System v2.0.0.0
04-01 00:40:53.092 D/Mono    ( 5079): Unloading image System.dll [0x7f041ff0].
04-01 00:40:53.092 D/Mono    ( 5079): Image addref System[0x7f04b030] -> System.dll[0x79befc10]: 16
[0:] 
04-01 00:40:53.092 D/Mono    ( 5079): Assembly Ref addref Cirrious.CrossCore[0x753c1000] -> System[0x79be85c0]: 15
MvxBind:Warning:  7.99 Failed to create target binding for binding CommandParameter for .
[0:] MvxBind:Warning:  7.99 Failed to create target binding for binding CommandParameter for .
04-01 00:40:53.112 I/mono-stdout( 5079): MvxBind:Warning:  7.99 Failed to create target binding for binding CommandParameter for .

我的片段绘制正确,但是MvxBind没有绑定.

My fragments are drawn exactly right, but the MvxBind isn't binding.

这是axml

<Button
    android:id="@+id/RegisterFragment_SignInButton"
    android:layout_below="@id/SignInFragment_Password"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/signin_text"
    local:MvxBind="Command SignInCommand; CommandParameter ." />

这是我的活动

public class AuthView : MvxTabsFragmentActivity
{
    private new AuthViewModel ViewModel { get { return (AuthViewModel)base.ViewModel; } }

    public AuthView() : base(Resource.Layout.AuthView, Resource.Id.actualtabcontent)
    {
    }

    protected override void AddTabs(Bundle args)
    {
        AddTab<SignInFragment>("Login", GetString(Resource.String.signin_text), args, ViewModel.SignInViewModel);
    }
}

从那里,我有一个片段

public class SignInFragment : MvxFragment
{
    public override View OnCreateView(LayoutInflater inflater, ViewGroup container,
                                      Bundle savedInstanceState)
    {
        var ignored = base.OnCreateView(inflater, container, savedInstanceState);
        return this.BindingInflate(Resource.Layout.SignInFragment, null);
    }
}

和两个ViewModels

and two ViewModels

public class AuthViewModel : MvxViewModel
{
    public AuthViewModel()
    {
        SignInViewModel = Mvx.IocConstruct<SignInViewModel>();
        RegisterViewModel = Mvx.IocConstruct<RegisterViewModel>();
    }

    public MvxViewModel SignInViewModel { get; set; }
    public MvxViewModel RegisterViewModel { get; set; }
}

public class SignInViewModel : MvxViewModel
{
    public SignInViewModel(ISignInCommand signInCommand)
    {
        _signInCommand = signInCommand;
    }

    private string _email;
    public string Email
    {
        get { return _email; }
        set { _email = value; RaisePropertyChanged(() => Email); }
    }

    private string _password;
    public string Password
    {
        get { return _password; }
        set { _password = value; RaisePropertyChanged(() => Password); }
    }

    private ISignInCommand _signInCommand;
    public ISignInCommand SignInCommand
    {
        get { return _signInCommand; }
        set { _signInCommand = value; RaisePropertyChanged(() => SignInCommand); }
    }

    public void ShowViewModel<T>() where T : IMvxViewModel
    {
        base.ShowViewModel<T>();
    }
}

我在哪里哪里出问题了?

Where might I be going wrong here?

推荐答案

我认为这与Fragment s

Android中的标准Button没有Command属性-它们具有Click事件.

Standard Buttons in Android don't have Command properties - they have Click events.

它们也没有CommandParameter属性-但是MvvmCross提供了CommandParameter转换器,允许您进行如下绑定:

They also don't have CommandParameter properties - but MvvmCross provides a CommandParameter converter to allow you to do bindings like:

local:MvxBind="Click CommandParameter(VMCommandName, VMCommandParameterName)"


如果要将CommandCommandParameter添加到MyButton,可以很容易地做到这一点:


If you want to add Command and CommandParameter to a MyButton this can be done quite easily:

public class MyButton : Button {
    public MyButton(Context c, IAttributeSet a) : base (c, a) {
        Click += (s,e) => {
           if (Command == null) return;
           if (!Command.CanExecute(CommandParameter)) return;
           Command.Execute(CommandParameter);
        }
    }
    public ICommand Command {get;set;}
    public object CommandParameter {get;set;}
}

在axml中用作:

<MyButton local:MvxBind="Command VMCommandName; CommandParameter VMCommandParameterName" />

这篇关于MvxTabsFragment无法创建目标绑定以绑定命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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