Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Finding the center point of an Image within a ContentControl

Posted on 2009-04-02
4
Medium Priority
?
752 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 2000 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

What is a Denial of Service (DoS)?

A DoS is a malicious attempt to prevent the normal operation of a computer system. You may frequently see the terms 'DDoS' (Distributed Denial of Service) and 'DoS' used interchangeably, but there are some subtle differences.

Question has a verified solution.

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

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…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

730 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