Hi all,
does anybody knows how to access the PageModel from the Page code behind?
I already tried using this: http://stackoverflow.com/questions/37917602/freshmvvm-access-pagemodel-from-page-code-behind?newreg=8426487c69544859ba861796ef300dfe
var pageModel = BindingContext as SamplePageModel;
however I always get my pageModel = null,
the thing is that I need to bind some TapGestureRecognizer to some methods/commands in my PageModel,
thank you all,
I found that you need to override this in your page:
protected override void OnBindingContextChanged() { base.OnBindingContextChanged(); var pageModel = BindingContext as YourFreshMVVMPageModel; // Modify the page based on the pageModel }
The PageModel construction seems to take place after the page Constructor, and this Event seems to fire at the right time and still make the page do what you want.
Answers
Hi @MCvel,
Is your VM inheriting from FreshBasePageModel ?
Are you keep the FreshMvvm pattern for directories? As for Pages the directory name MUST BE Pages and for PageModels MUST BE PageModels ?
Are you keep the FreshMvvm pattern for name of your View Models and Pages ? For Views Models MUST BE xptoPageModel and for Pages xptoPage.
My guess is that the name pattern was not applied.
I found that you need to override this in your page:
The PageModel construction seems to take place after the page Constructor, and this Event seems to fire at the right time and still make the page do what you want.
@jbravobr yes, the naming convention is properly configured, I actually have working some controls binded in XAML. Thanks!
@RobHeckart that did the trick, thanks man!