I can't seem to find this with Google. In WPF using MVVM, I have an InkCanvas for the view. Under this InkCanvas there are several more canvases providing different textual information.
Binding the InkCanvas with a PreviewMouseDown to the view model provides the viewmodel with the MouseButtonEventArgs from which I believe I can get the mouse position (relative to what?)
But, what is the best way to get the text elements from the lower canvases when the viewmodel does not have a reference to the view? How to do hit testing in the viewmodel???
ViewModel:
private RelayCommand inkCanvas_PreviewMouseDown;
public RelayCommand InkCanvas_PreviewMouseDown
{
get
{
if (inkCanvas_PreviewMouseDown == null)
{
inkCanvas_PreviewMouseDown = new RelayCommand( (p) => { this.method(p);
});
}
return inkCanvas_PreviewMouseDown;
}
}
private void method(Object e)
{
MouseButtonEventArgs args = e as MouseButtonEventArgs;
Point pt = args.GetPosition(null);
??? How to find the elements below the point on the other layers?
HitTestResult hit = VisualTreeHelper.HitTest(args.Source, pt); <--This is wrong.
}
XAML
<ink:CustomInkCanvas x:Name="inkcanvas" Panel.ZIndex="4"
Width="{x:Static h:Constants.widthCanvas}"
Height ="{x:Static h:Constants.heightCanvas}"
Background="Transparent"
DefaultDrawingAttributes="{Binding DDA}"
EditingMode="{Binding EditingMode}"
Strokes="{Binding Strokes}"
h:MouseBehaviour.PreviewMouseDownCommand="{Binding InkCanvas_PreviewMouseDown}"
>
</ink:CustomInkCanvas>