如何在MVVM中使用鼠标事件获取画布下的对象?

时间:2014-12-08 19:34:45

标签: wpf mvvm inkcanvas

在下面的XAML中,我将InkCanvas放在RichTextBox控件之上。在MVVM风格中,有没有办法用鼠标事件返回底层的RichTextBox对象? (这样可以获取RichTextBox中的鼠标位置和最近的单词)。

感谢您的任何帮助或想法。

<UserControl x:Class="Nova5.UI.Views.Ink.InkRichTextView"
           .....
   <Grid>    
         <f:SimpleRichTextBox Name="simplerichtextbox"  
         RichText="{Binding RichText, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}" 
         >
        <FlowDocument PageWidth="{Binding ElementName=simplerichtextbox, Path=ActualWidth}" />
    </fsc:SimpleRichTextBox>

    <InkCanvas   
        Height="{Binding ElementName=simplerichtextbox, Path=ActualHeight}"
        Width="{Binding ElementName=simplerichtextbox, Path=ActualWidth}"
        Background="Transparent" 
        DefaultDrawingAttributes="{Binding Pen}" 
        EditingMode="{Binding EditingMode}" 
        Strokes="{Binding Strokes}" 
        h:MouseBehaviour.MouseUpCommand="{Binding MouseUpCommand}"
        h:MouseBehaviour.PreviewMouseDownCommand="{Binding PreviewMouseDownCommand}"/>
  </Grid>
</UserControl>

0 个答案:

没有答案