Solved

Finding the center point of an Image within a ContentControl

Posted on 2009-04-02
4
733 Views
Last Modified: 2013-11-12
Hi Experts,

I have developed a custom class that inherits from ContentControl in WPF. WIthin this content control is a single Image.

I have then attached events to the class to handle (mouse wheel) zooming and (mouse click and drag) panning based on the mouse position.

The panning uses a TranslateTransform which the zooming also uses as well as a ScaleTransform.  I have created a TransformGroup and set the RenderTransform property of the Image within the ContentControl to the TransformGroup

I now wish to zoom and rotate (using RotateTransform) the image using buttons but I am having trouble getting the centerX and centerY right so the image zooms and rotates from the center point of the image.

Thanks in advance

Tom

0
Comment
Question by:TommyTwoPints
  • 2
  • 2
4 Comments
 
LVL 3

Author Comment

by:TommyTwoPints
ID: 24048313
Just to update, I don't need to get the center point of the image when i zoom with the mouse wheel as the image is also panned to the position of the mouse. I need to either create a virtual point at the center of the image or use the CenterX and CenterY  properties of the scale transform where CenterX and CenterY intersect at the center of the image
0
 
LVL 9

Expert Comment

by:peterdungan
ID: 24051577
Silverlight uses Dependency Properties to keep track of properties that can come from multiple sources, such as width and height. Access the dependency properties to get the height and width of the control like this:

YourControl.GetValue(WidthProperty);
YourControl.GetValue(HeightProperty);
0
 
LVL 3

Author Comment

by:TommyTwoPints
ID: 24051843
Hi Peter,
Thanks for the information. How could I use the GetValue function of the UIElement to work out the center point of an image that has potentially been scaled and moved within a ContentControl?
Thanks
Tom
0
 
LVL 9

Accepted Solution

by:
peterdungan earned 500 total points
ID: 24343776
double CHeight = (double)YourControl.GetValue(HeightProperty);
double CWidth = (double)YourControl.GetValue(WidthProperty);
Point CCentre = new Point();
CCentre.X = CWidth / 2;
CCentre.Y = CHeight / 2;
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now