Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Graphics Transformation Problem
Message
From
04/04/2009 12:16:13
 
 
General information
Forum:
ASP.NET
Category:
Windows Presentation Foundation (WPF)
Environment versions
Environment:
C# 3.0
Miscellaneous
Thread ID:
01392928
Message ID:
01393263
Views:
32
>Hi,
>
>Don't know if I can describe this well enough but:
>
>I have a Geometry which defines a shape (in the non-WPF meaning of the word). As an example assume it looks like a + sign.
>I use this as the Data property for a Path control.
>I add the Path to a Canvas and use the Path.RenderTransform to rotate it through 45 degrees (so that is appears on the Canvas more like an x shape)
>Now I want to create a new Path from this Path that gives the same appearance - but without using a Transform......
>(Well, not quite true: I could use a Transform - but the bounds of the new Path need to be relative to the Canvas)
>
>The above is a simple example - the actual solution will need to work with Paths using more complex Transforms
>
>Any suggestions?

In case anyone is interested: Where up is a UserControl (sited on a Canvas) containing a Path:
Path currentPath = (Path)up.Content;
Geometry oldGeometry = currentPath.Data;
//Add the Path Transform to the Geometry Transform:
TransformGroup tg = new TransformGroup();
if (oldGeometry.Transform != null)
    tg.Children.Add(oldGeometry.Transform);
tg.Children.Add(up.RenderTransform);
oldGeometry.Transform = new MatrixTransform(tg.Value);
// Use the new Bounds to determine new offset
double newLeft = oldGeometry.Bounds.Left; double newTop = oldGeometry.Bounds.Top;
TranslateTransform tt = new TranslateTransform(-newLeft, -newTop);
// and add that to the Geometry Transform:
tg.Children.Add(tt);
oldGeometry.Transform = new MatrixTransform(tg.Value);
// Adjust the position of the UserControl to compensate:
up.SetValue(Canvas.LeftProperty, ((double)up.GetValue(Canvas.LeftProperty)) + newLeft);
up.SetValue(Canvas.TopProperty, ((double)up.GetValue(Canvas.TopProperty)) + newTop);
//Adjust for new size:
up.Width = oldGeometry.Bounds.Width;
up.Height = oldGeometry.Bounds.Height;
//Get rid of the original UserControl transformation.
up.RenderTransform = Transform.Identity;
May be possible to simplify it but at least it works......
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform