0

How do you bind a dialog widget with a class? The class in question is defined in the Core project.

I could not find any example of this so far. I am comfortable binding an axml to a VM.

EDIT

Seems this tutorial https://github.com/MvvmCross/MvvmCross-Tutorials/tree/master/Fragments should get me started.

However I am not sure how to show a dialog when a listitem is clicked. Above sample maps a button click event to a method in the view, and the latter shows the dialog.

My listitem does not have a view associated to it. It has a viewmodel though. How do I go about showing a dialog when the listitem is clicked???

Also, what is the rational for the snippet in https://github.com/MvvmCross/MvvmCross-Tutorials/blob/master/Fragments/FragmentSample.UI.Droid/Views/HomeView.cs

var existingDialog = (NameDialogFragment)SupportFragmentManager.FindFragmentByTag(NameDialogTagName); if (existingDialog != null) existingDialog.ViewModel = HomeViewModel.Names;

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Telemat
  • 398
  • 2
  • 14

1 Answers1

1

How do you bind a dialog widget with a class?

As you've already found, you can do this using:

        var dialog = new NameDialogFragment();
        dialog.ViewModel = HomeViewModel.Names;
        dialog.Show(SupportFragmentManager, NameDialogTagName); 

My listitem does not have a view associated to it. It has a viewmodel though. How do I go about showing a dialog when the listitem is clicked???

In general I do this use the Interaction pattern - see UI action in middle of MvxCommand for a worked example

what is the rational for the snippet

It was probably to assist with Android rotation issues.

In general I don't do this much - I normally just turn Android's auto-rotation handling off and handle rotation myself instead.

Community
  • 1
  • 1
Stuart
  • 66,722
  • 7
  • 114
  • 165
  • Regarding the 2nd item (Interaction pattern), I ended up using a IMvxMessenger to notify the view, then let the view handle the display of the dialog. I did not know about the IMvxInteraction, will check it out. Any comment on which method is prefered? – Telemat Apr 22 '14 at 17:24
  • I've taken a look at the sample code. I could not get it to run. Anyway, in my case I need to display a fragment in my dialog. The example code does not cater for this scenario. Care to shed some light how I can inflate a fragment into the dialog? – Telemat Apr 23 '14 at 04:07