Solved

Finding the center point of an Image within a ContentControl

Posted on 2009-04-02
4
750 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

622 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