コード ビハインドを使用して InkCanvas にボタンを追加しました。理解できない理由として、
HitTestResult result = VisualTreeHelper.HitTest(pe.InkCanvas.Children[2], point_MouseDown);
ボタンのインデックスが2の場合、ボタンをクリックすると常に結果がnullになります。
子要素がクリックされたかどうかを判断する方法を知っている人はいますか?
どんな助けでも大歓迎です。(はい、インターネットを検索しましたがうまくいきませんでした。これがばかげた質問のように思えたら、申し訳ありません)。
システム: Windows 7、.net4.0 WPF C#
編集: Children[0] が RichTextBox の場合と同じことを行うと、上記の HitTest は null 以外を返します。理由を知っている人はいますか?
編集: 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>