简体   繁体   English

难以通过textblock.Inlines.Contain()进行点击测试?

[英]Difficulty with textblock.Inlines.Contain() with hit testing?

In the PreviewMouseDown event handler for my inkcanvas, I do hit testing for the underlying textBlock as below. 在用于我的画布的PreviewMouseDown事件处理程序中,我确实对基础textBlock进行了如下测试。 The hit testing correctly returns the Run element of the Inline collection. 命中测试正确返回Inline集合的Run元素。 So why is the same run element (of type inline) not seen as "contained" by the textBlock? 那么,为什么相同的运行元素(内联类型)不会被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. 在此先感谢您提供任何指导。

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. Run可以是Inline之一的(直接或间接)子元素,因此本身不是顶级Inline集合的元素。

In the following XAML, the Inlines collection contains two elements, a Run and a Bold. 在以下XAML中,Inlines集合包含两个元素,即Run和Bold。 The other Run is a child of the Bold element. 另一个Run是Bold元素的子代。

<TextBlock>
    <TextBlock.Inlines>
        <Run Text="Hello,"/>
        <Bold>
            <Run Text="World."/>
        </Bold>
    </TextBlock.Inlines>
</TextBlock>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM