Search code examples
mvvmcross

Set view element BindingContext - mvvm cross


Is it possible to set element data context in MvvmCross? Suppose I have:

<RelativeLayout>
     <TextView/> <TextView/>
</RelativeLayout>

and I'd like to set RelativeLayout data context to viewmodel property.

XAML equivalent of:

<Grid DataContext="{Binding someProperty}">
 <TextBlock/> <TextBlock/>
</Grid>

Solution

  • You can't currently do this directly in a single axml file in MvvmCross at present.

    However:

    1. You can use MvxFrameControl to load a sub-axml file (a bit like an include) and then set the DataContext for everything inside that sub-view

    2. MvvmCross is open source - so you can extend and adapt it...