Reputation: 398
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;
Upvotes: 0
Views: 186
Reputation: 66882
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.
Upvotes: 1