2010-01-13 11 views
7

मैं एक आयत फ्रेमवर्क तत्व द्वारा ओवरलैप किए गए नियंत्रण प्राप्त करने के लिए WPF कैनवास घटक पर एक आयताकार हिट परीक्षण करना चाहता हूं। मुझे सिल्वरलाइट की VisualTreeHelper.FindElementsInHostCoordinates विधि मिली, लेकिन स्पष्ट रूप से यह WPF में उपलब्ध नहीं है।डब्लूपीएफ में सिल्वरलाइट की FindElementsInHostCoordinates समतुल्य क्या है?

ऐसी कार्यक्षमता प्राप्त करने के लिए सबसे अच्छी विधि क्या है?

उत्तर

3

निकटतम समकक्ष VisualTreeHelper.HitTest है। यह सिल्वरलाइट के FindElementsInHostCoordinates के लिए काफी अलग तरीके से काम करता है, लेकिन आप इसे अपनी आवश्यकताओं के लिए उपयोग करने में सक्षम होना चाहिए।

3

जाना चाहिए तुम्हें सिल्वरलाइट में इस तरह एक फोन है

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)); 

होना चाहिए आप के लिए GeometryHitTestParameters बजाय PointHitTestParameters उपयोग कर सकते हैं एक रेक्ट-टेस्ट करें।

संबंधित मुद्दे