Binding in MvvmCross from a XAML view's codebehind
For a view, I have it hooking onto this.ViewModel.PropertyChanged like so:
ViewModel.PropertyChanged += (s, e) =>
{
if (e.PropertyName == "CurrentImage")
DoStuff();
};
This is because XAML is not flexible enough for me to achieve what I'd
like directly without codebehind, and also because it's code that is
purely related to WinRT/XAML and not the core portable project.
However during the view's constructor, the ViewModel property is null,
thus it was worked around like so:
this.Loaded += (s2, e2) =>
ViewModel.PropertyChanged += (s, e) =>
{
if (e.PropertyName == "CurrentImage")
DoStuff();
};
I figure this (in addition to using a string to refer to a property) is
probably not very clean, and there probably should be a better way to
achieve what I'd like. Is there a more ideal approach?
No comments:
Post a Comment