PC Review


Reply
Thread Tools Rate Thread

Associate WPF Graphic with a Class

 
 
Wonko the Sane
Guest
Posts: n/a
 
      29th Nov 2007
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.
 
Reply With Quote
 
 
 
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      29th Nov 2007
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]
- (E-Mail Removed)

"Wonko the Sane" <Wonko the (E-Mail Removed)am> wrote in message
news:F6DFDF35-CB80-4EC5-A26D-(E-Mail Removed)...
> 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.



 
Reply With Quote
 
Walter Wang [MSFT]
Guest
Posts: n/a
 
      30th Nov 2007
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.

http://www.codeproject.com/WPF/Dragg...tsInCanvas.asp

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

http://dvuyka.spaces.live.com/blog/cns!305B02907E9BE19A!144.entry

Hope this helps.


Regards,
Walter Wang ((E-Mail Removed), 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.

 
Reply With Quote
 
Walter Wang [MSFT]
Guest
Posts: n/a
 
      5th Dec 2007
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 ((E-Mail Removed), 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.

 
Reply With Quote
 
 
 
Reply

« test | Pascal => C# »
Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calendar Invite with Graphic Grows Disproportional to Graphic Size Jami Microsoft Outlook Calendar 0 18th May 2010 07:24 PM
Associate an attribute with a type other than class definition Tom Microsoft Dot NET 0 17th Sep 2004 05:55 PM
Associate an attribute with a type other than class definition Tom Microsoft C# .NET 0 17th Sep 2004 05:54 PM
new class w/ graphic objects Tony Rizzo Microsoft Excel Programming 1 7th Jun 2004 02:18 PM
Question about S-VIDEO and connecting my TV to my computer (via graphic 9600 Pro graphic card).... Melandre ATI Video Cards 7 4th Nov 2003 04:28 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:10 PM.