Listen to the event when the border of one UI element crosses the border of the other UI element
-
I need to define a customized event which detects whether the border of one UI element crosses the border of the other UI element. Make this assumption that both UI elements are on a Canvas, and they have the relative coordinates toward the boundary of the Canvas which are Canvas.Left and Canvas.Bottom. My initial thought was to create a function which checks the relative coordinates of these two elements and raise the event whenever their coordinates are identical. Then, I realized it was rather awkward because each element has its area and it can not be considered as a pixel. I have contemplated this puzzle for quite some time but still I can not come out with anything. Would anyone be kind enough to help me out on this I will be grateful. Thanks in advance
Someone was born greatness; Someone achieved greatness; Someone have the greatness thrust upon him;
-
I need to define a customized event which detects whether the border of one UI element crosses the border of the other UI element. Make this assumption that both UI elements are on a Canvas, and they have the relative coordinates toward the boundary of the Canvas which are Canvas.Left and Canvas.Bottom. My initial thought was to create a function which checks the relative coordinates of these two elements and raise the event whenever their coordinates are identical. Then, I realized it was rather awkward because each element has its area and it can not be considered as a pixel. I have contemplated this puzzle for quite some time but still I can not come out with anything. Would anyone be kind enough to help me out on this I will be grateful. Thanks in advance
Someone was born greatness; Someone achieved greatness; Someone have the greatness thrust upon him;
I'm not sure exactly what you're looking for... For rectangular elements, if you don't want to code it yourself, you could probably use the Rect structure and its Intersect() method...if the method returns Rect.Empty then the elements don't overlap.
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
I'm not sure exactly what you're looking for... For rectangular elements, if you don't want to code it yourself, you could probably use the Rect structure and its Intersect() method...if the method returns Rect.Empty then the elements don't overlap.
Mark Salsbery Microsoft MVP - Visual C++ :java:
Thanks Mark for your information. I did a little bit of research on the method you provided me, and I found out this Intersect() method belongs to a GDI+ rectangle structure and it's not supported in WPF shapes. Are there any other methods which can substitute this one? BTW, you are right about what I am looking for. In my program, I need to use an event to detect the intersection of different WPF UI elements in order to process some task once they cross over with each other.
Someone was born greatness; Someone achieved greatness; Someone have the greatness thrust upon him;
-
Thanks Mark for your information. I did a little bit of research on the method you provided me, and I found out this Intersect() method belongs to a GDI+ rectangle structure and it's not supported in WPF shapes. Are there any other methods which can substitute this one? BTW, you are right about what I am looking for. In my program, I need to use an event to detect the intersection of different WPF UI elements in order to process some task once they cross over with each other.
Someone was born greatness; Someone achieved greatness; Someone have the greatness thrust upon him;
YouMiss wrote:
this Intersect() method belongs to a GDI+ rectangle structure and it's not supported in WPF shapes
You looked at the wrong one. Rect Structure (System.Windows)[^]
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
YouMiss wrote:
this Intersect() method belongs to a GDI+ rectangle structure and it's not supported in WPF shapes
You looked at the wrong one. Rect Structure (System.Windows)[^]
Mark Salsbery Microsoft MVP - Visual C++ :java: