MvxTabsFragment Failed to create target binding for binding Command for

前端 未结 1 1311
孤街浪徒
孤街浪徒 2021-01-27 06:31

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.

MvxB         


        
1条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-27 07:04

    I don't think this has anything to do with Fragments

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

    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)"
    

    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;}
    }
    

    Used in axml as:

    
    

    0 讨论(0)
提交回复
热议问题