【发布时间】:2014-06-10 22:48:29
【问题描述】:
我通过代码隐藏向 InkCanvas 添加了一个按钮。由于我无法理解的原因,
HitTestResult result = VisualTreeHelper.HitTest(pe.InkCanvas.Children[2], point_MouseDown);
按钮的索引为 2,当我点击按钮时,结果总是为空。
有人知道如何判断子元素是否被点击了吗?
任何帮助将不胜感激。 (是的,我已经搜索了互联网但没有成功。如果这看起来是一个愚蠢的问题,我深表歉意)。
系统:Windows 7,.net4.0 WPF C#
编辑:如果我在 Children[0] 是 RichTextBox 的情况下做同样的事情,那么上面的 HitTest 返回非空值。有人知道为什么吗?
编辑:RichTextBox 和 Button 都在代码隐藏中添加,XAML 是:
<Grid Height="{x:Static local:pe.heightCanvas}" >
<!--NotepadCanvas. Canvas used to place user writing lines and borders.-->
<Canvas Name="NotePadCanvas" Panel.ZIndex="0"
Width="{x:Static local:pe.widthCanvas}"
Height="{x:Static local:pe.heightCanvas}"
Background="{Binding documenttype, Converter={StaticResource inkCanvasBackgroundConverter}}" />
<!--BackgroundCanvas. Canvas used for special highlighting of seleted items-->
<Canvas Name="BackgroundCanvas" Panel.ZIndex="1"
Width="{x:Static local:pe.widthCanvas}"
Height="{x:Static local:pe.heightCanvas}"
Background="Transparent" />
<!--FormsCanvas. Canvas used to place formatted text from lists, etc.-->
<Canvas Name="FormsCanvas" Panel.ZIndex="2"
Width="{x:Static local:pe.widthCanvas}"
Height="{x:Static local:pe.heightCanvas}"
Background="Transparent" />
<!--TranscriptionCanvas. Canvas used to place recognized ink from the InkAnalyzer-->
<Canvas Name="TranscriptionCanvas" Panel.ZIndex="3"
Width="{x:Static local:pe.widthCanvas}"
Height="{x:Static local:pe.heightCanvas}"
Background="Transparent" />
<!--InkCanv. Top most canvas used to gather handwritten ink strokes from the user. EditingMode="Ink" Gesture="OnGesture" -->
<local:CustomInkCanvas x:Name="InkCanvas" Panel.ZIndex="4"
Width="{x:Static local:pe.widthCanvas}"
Height ="{x:Static local:pe.heightCanvas}"
Background="Transparent"
AllowDrop="True" Drop="InkCanvas_Drop"/>
</Grid>
【问题讨论】:
-
你能分享你的 xaml 树吗?所以我们可以看看并尝试模拟。