Reputation: 5394
In the PreviewMouseDown event handler for my inkcanvas, I do hit testing for the underlying textBlock as below. The hit testing correctly returns the Run element of the Inline collection. So why is the same run element (of type inline) not seen as "contained" by the textBlock?
void CustomInkCanvas_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
CustomInkCanvas cink = sender as CustomInkCanvas;
TextBlock tb = GetVisualChild<TextBlock>(cink);
Point p = e.GetPosition(tb);
/** THIS IS CORRECT AND RETURNS THE CORRECT VALID RUN (of type Inline).
Run run = tb.InputHitTest(p) as Run;
??? BUT DEBUG HERE STATES THAT THE RUN IS NOT CONTAINED BY THE TEXTBLOCK ??
Debug.Assert(tb.Inlines.Contains(run) != true, "Where is the run?");
}
Thanks in advance for any guidance with this.
Upvotes: 0
Views: 76
Reputation: 128146
The Run may be a (direct or indirect) child element of one of the Inlines, and hence not itself be an element of the top-level Inline collection.
In the following XAML, the Inlines collection contains two elements, a Run and a Bold. The other Run is a child of the Bold element.
<TextBlock>
<TextBlock.Inlines>
<Run Text="Hello,"/>
<Bold>
<Run Text="World."/>
</Bold>
</TextBlock.Inlines>
</TextBlock>
Upvotes: 1