Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Listen to the event when the border of one UI element crosses the border of the other UI element

Listen to the event when the border of one UI element crosses the border of the other UI element

Scheduled Pinned Locked Moved WPF
designhelp
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    YouMiss
    wrote on last edited by
    #1

    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;

    M 1 Reply Last reply
    0
    • Y YouMiss

      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;

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      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:

      Y 1 Reply Last reply
      0
      • M Mark Salsbery

        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:

        Y Offline
        Y Offline
        YouMiss
        wrote on last edited by
        #3

        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;

        M 1 Reply Last reply
        0
        • Y YouMiss

          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;

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          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:

          Y 1 Reply Last reply
          0
          • M Mark Salsbery

            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:

            Y Offline
            Y Offline
            YouMiss
            wrote on last edited by
            #5

            Thanks very much, I probably should have searched harder, I will try it out!

            Someone was born greatness; Someone achieved greatness; Someone have the greatness thrust upon him;

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups