Scale a Polyline - Transformation??  
Author Message
F. Gsell





PostPosted: Windows Presentation Foundation (WPF), Scale a Polyline - Transformation?? Top

Hi together,

I have got a polyline object which is used for drawing a chart on a canvas object. Now I want to tranform the polyline object to fit on the canvas. So first I want to calculate the needed scaletransform object. To do this, I tried to get the width and heigth of the polyline so that I can calculate the transformation in respect to the canvas. But I alwas get "0,0" for the width and height of the polyline (RenderSize, ActualHeight, ActualWidth and so on).

So my question, how can I calculate the necessary transformation when I can't get the current width or height of the polyline object

Cheers,
Franz




Visual Studio 200832  
 
 
Thilak Nathen





PostPosted: Windows Presentation Foundation (WPF), Scale a Polyline - Transformation?? Top

What is the polyline sitting on A custom control

If you render your polyline on a class that inherits from FrameworkElement, you get to override the OnRender method. The drawingContext.RenderSize should contain the width and height you need.


 
 
Anthony Hodsdon - MSFT





PostPosted: Windows Presentation Foundation (WPF), Scale a Polyline - Transformation?? Top

Please see my other post @ http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=826865&SiteID=1. The shape classes have the power to do this resizing for you. To enable this functionality, you'll want to set the Stretch property on Polyline to either Fill or Uniform. Note that you'll also need to make sure that the parent element has the ability to resize its children (Grid, for instance, does, but Canvas does not).

You might well wonder what all those Width, ActualWidth, etc... properties are for, and why they don't seem to work when you use them. ActualWidth is just about what you want, the gotcha is that it will only report an accurate value after layout has been run (it's layout, after all, that determines what the size of the polyline will be), and once layout has been run, it's already too late to start inserting transforms in. Width, on the other hand, is a hint to tell layout what size you'd like the shape to be. Hence, it's very rarely useful to read its value.