2014-04-01 63 views
0

我正在嘗試創建MvxTabsFragmentActivity並將片段上的按鈕綁定到命令。我收到的問題是以下錯誤。MvxTabsFragment無法爲綁定命令創建目標綁定

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沒有約束力。

這裏的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

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

我在哪裏可能會出錯?

回答

1

我不認爲這有什麼關係Fragment小號

標準Button S IN的Android不具備Command性質 - 它們有Click事件。

他們也沒有CommandParameter性能 - 但MvvmCross提供了CommandParameter轉換器允許你這樣做綁定,如:

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

如果你想添加CommandCommandParameterMyButton這樣可以可以很容易實現:

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" /> 
+0

啊是的,它似乎我事實上曾經遇到過這個。但是,由於Android項目之間的距離太遠,所以它會讓我失望。 –

+0

你是對的......我只是需要一些睡眠(和一個新鮮的頭腦)。 –