473,385 Members | 1,806 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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.
Nov 29 '07 #1
3 1622
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]
- mv*@spam.guard.caspershouse.com

"Wonko the Sane" <Wonko the Sa**@nospam.nospamwrote in message
news:F6**********************************@microsof t.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.

Nov 29 '07 #2
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 (wa****@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.

Nov 30 '07 #3
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 (wa****@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.

Dec 5 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Joe exCSSive | last post by:
Hi, folks: I'm back...and now I'm really stuck !! I have a graphic ( http://www.sundialontario.com/images/makeitatable.jpg ) that I would like to convert to CSS and I'm not sure how to do...
0
by: Tom | last post by:
Is there a way to associate an attribute with a type aside from placing it on the class definition. Here is what I mean I make a new UITypeEditor for Drawing.Color. Now in my project I alway...
7
by: someone | last post by:
Let's say I have a Session timeout of 20 minutes. If the browser periodically request a graphic file, will that keep its Session alive? What keeps the Session alive? Is it the Session cookie that...
1
by: hamil | last post by:
I am trying to print a graphic file (tif) and also use the PrintPreview control, the PageSetup control, and the Print dialog control. The code attached is a concatination of two examples taken out...
1
by: Niclas | last post by:
Hi, in ASP .Net, I can associate a value with and item in a dropdown list, for example when binding to a list of employees, I can store the employeeid as a value associated with each name in in...
1
by: icepick72 | last post by:
On an academic note, I want to copy a Graphic to an Image (Bitmap). I have the Graphic object but not the origin image from which it originates; this is because I'm overriding the PrintDocument...
8
by: Brian Ward | last post by:
I am looking for a simple way to set the image transparency in a PictureBox. I have a moving PictureBox containing a graphic image .. moving by incrementing its Left property. The background...
0
by: Nathan Sokalski | last post by:
I am using an *.aspx page with a querystring to access graphics that I am using in rollovers. I am using Response.ContentType and using Response.WriteFile(). This sends the graphic perfectly fine,...
1
by: nt5515 | last post by:
hey Im trying to make a game of pairs (the memory game) i have set up a grid which displays a graphic for the card back. im trying to link the edit menu to choose the graphic to be displayed. i've...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.