Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EnsureBindingContextSet method missing from the MvxAppCompatDialogFragment class

I am trying to create a custom dialog using the MvxAppCompatDialogFragment and AlertDialog.Builder classes. I've looked through every bit of example that I could find on the internet but I'm stuck on this one part. Every single one of those working samples that I've found used the base.EnsureBindingContextSet method inside the overridden OnCreateDialog method. But every time I use that method, the compiler keeps giving me this error:

'MvxAppCompatDialogFragment<MyViewModel>' does not contain a definition for 'EnsureBindingContextSet'

So I tried to look for others who have this problem. But no matter how hard I searched, no matter the keywords that I use, I really can't find anyone who has this same problem. I hope someone can help me with this problem.

The version of MvvmCross that I use is 6.0.1. Here is the part of my code which gives me problems, in case it might help. It's still quite empty since it won't work on my first test.

public override Dialog OnCreateDialog(Bundle savedInstanceState)
{
    base.EnsureBindingContextSet(savedInstanceState);

    var view = this.BindingInflate(Resource.Layout.DurationDialogFragment, null);

    var builder = new AlertDialog.Builder(Activity);

    builder
        .SetView(view)
        .SetPositiveButton("Confirm", (s, e) => { })
        .SetNegativeButton("Cancel", (s, e) => { ViewModel.CloseCommand.Execute(); });

    var dialog = builder.Create();

    dialog.SetCanceledOnTouchOutside(false);

    return dialog;
}
like image 403
DL Techy Avatar asked Mar 24 '26 03:03

DL Techy


1 Answers

Ok, I've made it work. I've found the source code on how the EnsureBindingContextSet was implemented and used it instead.

I've actually found the latest source code from Martin's github page and it looks like the EnsureBindingContextSet method is gone. Here's the link if you want to check: https://github.com/MvvmCross/MvvmCross/blob/develop/MvvmCross.Android.Support/V7.AppCompat/MvxAppCompatDialogFragment.cs

So what I did was to type:

this.EnsureBindingContextIsSet();

and used intellisense to find the proper using statement to use, which is:

using MvvmCross.Droid.Support.V4;

Also using intellisense, I think that the problem is that the new EnsureBindingContextIsSet extension method does not accept a Bundle object as a parameter anymore which resulted in the method's removal.

Seeing as I can't find any trace of this problem in the internet, I hope that this will help somebody who comes into this exact problem in the future.

like image 57
DL Techy Avatar answered Mar 25 '26 15:03

DL Techy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!