Solved

Finding the center point of an Image within a ContentControl

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Dot Net 4.6.1 installation fails on W2012 R2 server 14 40
Complex SQL statement in VB.NET 7 31
Code enhancement 4 22
How can I do Unit Testing with Session ? 1 13
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

830 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