I need to be able to run methods on a XAML element in my ViewModel, I have 3 files - DataPrepPage.cs, DataPrepPage.xaml and DataPrepViewModel.cs.
In my XAML(DataPrepPage.xaml) page I have the element like this:
<esriUI:MapView x:Name="MapElement"
Map="{Binding Map}"/>
I set my binding context on the parent grid element like this:
<Grid.BindingContext>
<local:DataPrepViewModel/>
</Grid.BindingContext>
Of course I can access my MapView element and methods in the code-behind like this for example:
MapElement.GraphicsOverlays.Add(MyOverlay);
So the problem is I need to be able to do this in the ViewModel but the x:Name does not expose it to my ViewModel.
At the moment I have a static in my ViewModel
public static MapView MapView;
And I assign my element to it in the constructor of my page code-behind:
public DataPrepPage ()
{
InitializeComponent ();
DataPrepViewModel.MapView = MapElement;
}
Which allows me to do this in my ViewModel:
MapView.GraphicsOverlays.Add(MyOverlay);
So the question is:
How do I expose the element to my ViewModel without using a static? || How can I run methods on an element from the ViewModel?