J'ai ajouté un bouton à un InkCanvas à l'aide de code-behind. Pour des raisons que je ne comprends pas,Hit test sur enfant de InkCanvas
HitTestResult result = VisualTreeHelper.HitTest(pe.InkCanvas.Children[2], point_MouseDown);
où le bouton a l'index de 2, résulte toujours en résultat étant nul lorsque je clique sur le bouton.
Quelqu'un sait-il comment déterminer si un élément enfant a été cliqué?
Toute aide sera appréciée. (Oui, j'ai cherché sur Internet sans succès, je m'excuse si cela semble une question stupide).
Système: Windows 7, .net4.0 WPF C#
Edit: Si je fais la même chose où les enfants [0] est un RichTextBox, le plus haut HitTest resturns non nulle. Quelqu'un avec une idée de pourquoi?
Edit: Les deux RichTextBox et le bouton sont ajoutés dans le code-behind, le XAML est:
<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>
pourriez-vous partager votre arbre xaml? afin que nous puissions jeter un coup d'œil et essayer de simuler. – pushpraj