2016-04-29 10 views
0

私はドロイド部分にMvvmcross/Xamarinアプリケーションに関する問題があります。 私は、私は1つの項目を選択すると、私は私のSelectedActionをdroid.axmlXamarin.Android/MvvmCross:MvxSpinnerでのナビゲーション

<MvxSpinner 
    android:id="@+id/action_spinner" 
    android:layout_weight="2" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    local:MvxItemTemplate="@layout/item_spinner" 
    local:MvxDropDownItemTemplate="@layout/item_spinnerdropdown" 
    local:MvxBind="ItemsSource Actions;SelectedItem ActionSelected" /> 

を設定する「MvxSpinnerメニュー」ウィッヒは夫婦のリストにバインドされ ViewModel.cs

private List<CoupleIntString> _actions = new List<CoupleIntString>() { 
    new CoupleIntString(0,"Actions"), 
    new CoupleIntString(1, "Mail"), 
    new CoupleIntString(2,"Imprimer"), 
    new CoupleIntString(3, "Totaux"), 
    new CoupleIntString(4, "Fiche client") 
}; 

public List<CoupleIntString> Actions { 
    get { return _actions; } 
    set { 
     _actions = value; 
     RaisePropertyChanged(() => Actions); 
    } 
} 

を行っていますFirstViewModelを開き、ロードするビューモデルを表示します。

public CoupleIntString ActionSelected { 
    set { 
     int xx = value.intPart; 
     switch (xx) { 
     case 1: //mail 
      GoToMailCommand.Execute(); 
      break; 
     case 2: //impression 
      GoToImpressionCommand.Execute(); 
      break; 
     case 3: //totaux 
      GoToTotauxCommand.Execute(); 
      break; 
     case 4: //impression 
      GoToDetailsClientCommand.Execute(); 
      break; 
     default: 
      break; 
     } 
    } 

しかし、私は戻ってFirstViewModelに来るとき、それは自動的にSelectedActionを再設定し、第二のViewModelに戻ります。 私はSelectedActionをInit、ReloadState、Start、InitFromBundle、ReloadFromBundleのどれにも設定しようとしませんでしたが、これらの呼び出しのあとに、前に選択した値を持つ別のものがあり、どこから来たのかわかりません。

答えて

0

私は0

var spinner = FindViewById<MvxSpinner>(Resource.Id.action_spinner); 
spinner.ItemSelected += Spinner_ItemSelected; 
+0

おかげで、これは動作しません。 。また、私たちはドロイドの部分でできるだけコードを少なくしようとしています。 –

0

へのSelectedItemリスナーと設定のSelectedItemを追加することを提案するだろうMvvmCrossがMvxSpinnerのために結合SelectedItem目標を持って、あなたは、ほぼ右のあなたのコードです。しかし、あなたは仕事への結合SelectedItemのためにpropertyの代わりにコマンドを使用する必要があります。

private MvxCommand<CoupleIntString> _itemSelected; 
public ICommand ItemSelected => 
    _itemSelected = _itemSelected ?? 
     (_itemSelected = new MvxCommand<CoupleIntString>(DoItemSelected)); 

private void DoItemSelected(CoupleIntString item) 
{ 
    ActionSelected = item; 
} 

その後のようなあなたの結合に見えるように:あなたの助けのための

local:MvxBind="ItemsSource Actions; SelectedItem ItemSelected" 
+0

あなたの助けてくれてありがとうございますが、1つのアイテムを選択するとうまくいきません。 MvxBind:警告:62,44バインド - ターゲットプロパティでSetValueが無視され、 となり、何も起こりません。 (コードを編集しました:ICommand _itemSelectedをMvxCommand _itemSelectedに変更しました) –