2016-04-28 4 views
0

В FundamentalView.cs У меня есть событие click, которое вызывает фрагмент из нижней части представления с параметрами (добавлением нового человека и новыми вычислениями).ViewModel не вызывается в MVVMCross

var addButton = view.FindViewById<ImageButton>(Resource.Id.addButton); 
addButton.Click += OnAddButtonClick; 

void OnAddButtonClick(object sender, System.EventArgs e) 
{ 
    var dialog = new CardDialogView(); 
    dialog.Show(((MainView)Activity).SupportFragmentManager, "CardDialogView");   
} 

CardDialogView.axml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:local="http://schemas.android.com/apk/res-auto" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#FFFFFF"> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:drawableLeft="@drawable/dash_add_computer" 
     android:textColor="@color/primary_text" 
     android:textSize="16sp" 
     android:text="New Calculation" 
     local:MvxBind="Click NewCalculationCommand"/> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:drawableLeft="@drawable/dash_add_head" 
     android:drawablePadding="28dp" 
     android:textColor="@color/primary_text" 
     android:textSize="16sp" 
     android:text="New Person" /> 
</LinearLayout> 

CardDialogView.cs

public class CardDialogView : MvxDialogFragment<CardDialogViewModel> 
{ 
    public override Dialog OnCreateDialog(Bundle savedState) 
    { 
     ...... 
     return dialog ; 
    } 
} 

Следующие соответствующие ViewModel не дозвонились? Интересно, что мне не хватает?

CardDialogViewModel.cs

public class CardDialogViewModel : MvxViewModel 
{ 

    public ICommand NewCalculationCommand 
    { 
     get 
     { 
     return new MvxCommand(() => ShowViewModel<NewItemViewModel>(new { date = DateTime.Now })); 
     } 
    } 
} 

ответ

2

Вы пропали без вести это от CardDialogView.axml расположения файла xmlns:local="http://schemas.android.com/apk/res-auto"

CardDialogView.axml должен быть таким:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:local="http://schemas.android.com/apk/res-auto" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#FFFFFF"> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:drawableLeft="@drawable/dash_add_computer" 
     android:textColor="@color/primary_text" 
     android:textSize="16sp" 
     android:text="New Calculation" 
     local:MvxBind="Click NewCalculationCommand"/> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:drawableLeft="@drawable/dash_add_head" 
     android:drawablePadding="28dp" 
     android:textColor="@color/primary_text" 
     android:textSize="16sp" 
     android:text="New Person" /> 
</LinearLayout> 

Подумайте, что вам нужно установить ViewModel на CardDialogView так:

void OnAddButtonClick(object sender, System.EventArgs e) 
    { 
     var dialog = new CardDialogView(); 
     dialog.ViewModel = new CardDialogViewModel(); 
     dialog.Show(SupportFragmentManager, "CardDialogView"); 
    } 
+0

я добавил уже, но забыл включить в мой вопрос, он не работает – hotspring

+0

Ах круто thougth так, как это Probs Wouldnt строить, какую версию из MVVMCross вы используете? –

+0

Я использую Версия 4.0 – hotspring

Смежные вопросы