Solved

Finding the center point of an Image within a ContentControl

Posted on 2009-04-02
4
739 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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 …
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

808 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