Associate WPF Graphic with a Class

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?V29ua28gdGhlIFNhbmU=?=

    #1

    Associate WPF Graphic with a Class

    Hi All,

    I have the following (much-simplified) situation. I have a class, part of
    which involves drawing graphics on a Canvas. I may have a number of
    instances of these graphics, which may include a line, two rectangles used as
    endpoints, and perhaps a label for the line.

    I want to somehow later associate a graphic on the canvas with an instance
    of the class. For instance, if the user selects an endpoint and drags it, I
    want to resize the line, and perhaps update some information in a database
    based on that resize.

    I'm just looking for a graceful way to do this. I have a solution, but it
    seems inelegant. Any advice or a pointer to an example would be
    appreciated...

    Thanks.
  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Associate WPF Graphic with a Class

    Hmm, instead of drawing the lines and whatnot, have you considered
    making the lines (with the associated elements) and rectangles UIElements
    themselves? They would have their own dependency properties, etc, etc, and
    then you would add them to the canvas.

    Then, in relation to your class, you could just have it listen to the
    event handlers for the dependency properties you expose and do something
    when the value changes.

    For example, for a Line class, you would have a Point1 dependency
    property and a Point2 dependency property (maybe, it's up to you) which
    expose the endpoints of the line. Then, you could just register to receive
    change notifications in your class that you want to receive updates.

    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Wonko the Sane" <Wonko the Sane@nospam.nos pamwrote in message
    news:F6DFDF35-CB80-4EC5-A26D-B0087510687C@mi crosoft.com...
    Hi All,
    >
    I have the following (much-simplified) situation. I have a class, part of
    which involves drawing graphics on a Canvas. I may have a number of
    instances of these graphics, which may include a line, two rectangles used
    as
    endpoints, and perhaps a label for the line.
    >
    I want to somehow later associate a graphic on the canvas with an instance
    of the class. For instance, if the user selects an endpoint and drags it,
    I
    want to resize the line, and perhaps update some information in a database
    based on that resize.
    >
    I'm just looking for a graceful way to do this. I have a solution, but it
    seems inelegant. Any advice or a pointer to an example would be
    appreciated...
    >
    Thanks.

    Comment

    • Walter Wang [MSFT]

      #3
      Re: Associate WPF Graphic with a Class

      I agree with Nicholas. The WPF-way of doing this is using UIElements on the
      canvas. Josh Smith has created a customized Canvas that could let you move
      around any UIElements on it.



      To resize an UIElement, you will need to use Adorner:

      http://dvuyka.spaces.l ive.com/blog/cns!305B02907E9 BE19A!144.entry

      Hope this helps.


      Regards,
      Walter Wang (wawang@online. microsoft.com, remove 'online.')
      Microsoft Online Community Support

      =============== =============== =============== =====
      When responding to posts, please "Reply to Group" via your newsreader so
      that others may learn and benefit from your issue.
      =============== =============== =============== =====

      This posting is provided "AS IS" with no warranties, and confers no rights.

      Comment

      • Walter Wang [MSFT]

        #4
        RE: Associate WPF Graphic with a Class

        Hi,

        I'm writing to check the status of this post. Please feel free to let me
        know if there's anything else I can help. Thanks.


        Regards,
        Walter Wang (wawang@online. microsoft.com, remove 'online.')
        Microsoft Online Community Support

        =============== =============== =============== =====
        When responding to posts, please "Reply to Group" via your newsreader so
        that others may learn and benefit from your issue.
        =============== =============== =============== =====

        This posting is provided "AS IS" with no warranties, and confers no rights.

        Comment

        Working...