7

Rectangleフレームワーク要素によってオーバーラップするコントロールを取得するために、WPFCanvasコンポーネントで長方形ヒットテストを実行したいと思います。SilverlightのVisualTreeHelper.FindElementsInHostCoordinates方法を見つけましたが、WPFでは使用できないようです。

そのような機能を実現するための最良の方法は何ですか?

4

2 に答える 2

3

最も近いものはVisualTreeHelper.HitTestです。これはSilverlightとは大幅に異なる動作FindElementsInHostCoordinatesをしますが、必要に応じて使用できるはずです。

于 2010-01-13T20:06:53.880 に答える
3

Silverlightでこのような電話があったとします

var result = VisualTreeHelper.FindElementsInHostCoordinates(myPoint, myUIElement);

この場合、このWPFコードには同等のものが必要ですresult

var result = new List<DependencyObject>(); 
                         //changed from external edits, because VisualHit is
                         //only a DependencyObject and may not be a UIElement
                         //this could cause exceptions or may not be compiling at all
                         //simply filter the result for class UIElement and
                         //cast it to IEnumerable<UIElement> if you need
                         //the very exact same result including type

VisualTreeHelper.HitTest(
    myUiElement,
    null,
    new HitTestResultCallback(
        (HitTestResult hit)=>{
            result.Add(hit.VisualHit);
            return HitTestResultBehavior.Continue;
        }),
    new PointHitTestParameters(myPoint));

特別な場合には、Rect-Testを実行するGeometryHitTestParameters代わりに使用することをお勧めします。PointHitTestParameters

于 2013-05-14T10:14:10.223 に答える