0

How can I get the transformed values of a UIElement without adding it to the visual tree in .net 3.5 in WPF?

Achievement: A UIElement (Canvas) contains a transformation matrix and several Paths (Shapes) as content. How can I get the transformed paths (matrix transformations like scale, rotation, ... already calculated)?

Assume we're having the following Path

  <Path Stroke="Black" StrokeThickness="3.0">
    <Path.Data>
      <PathGeometry>
        <PathFigure StartPoint="355,-110">
          <LineSegment Point="0,-110" />
        </PathFigure>
        <PathFigure StartPoint="310,-125">
          <LineSegment Point="355,-110" />
          <LineSegment Point="310,-95" />
        </PathFigure>
      </PathGeometry>
    </Path.Data>
  </Path>

... how can we get the transformed result attached to a Canvas, e.g. if the Path is scaled by a value of 2 in x and y axis?

Expected result for the example:

  <Path Stroke="Black" StrokeThickness="3.0">
    <Path.Data>
      <PathGeometry>
        <PathFigure StartPoint="700,-220">
          <LineSegment Point="0,-220" />
        </PathFigure>
        <PathFigure StartPoint="620,-250">
          <LineSegment Point="710,-220" />
          <LineSegment Point="620,-190" />
        </PathFigure>
      </PathGeometry>
    </Path.Data>
  </Path>

I want to traverse through a generated xml string after the transformation to use it in non-wpf code. How can I get the transformed paths? All the methods I tried (GetChild etc.) delivered the original paths without transformation.

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Beachwalker
  • 7,685
  • 6
  • 52
  • 94
  • What do you mean with "transformed values"? Please provide a few more details about your problem or what you want to achieve. – Clemens Feb 28 '12 at 11:42
  • Ok, made the problem description more precise. – Beachwalker Feb 28 '12 at 14:43
  • Still not quite clear to me. How would you get the "transformed values" (i mean the coordinates) if you added the Canvas to the visual tree? If your question is about how to directly transform paths or geometries (without Canvas), the answer is that they also have a Transform property. Their Transform properties might even be set to the same transform object, e.g. a single MatrixTransform. – Clemens Feb 28 '12 at 15:18
  • I want to traverse through a generated xml string to use it in non-wpf code. How can I get the transformed paths? All the methods (GetChild etc.) delivers the original paths without transformation. – Beachwalker Feb 28 '12 at 16:54
  • 1
    Hello Stegi, This is because the Path itself is not modified. A transdormation is applied to it, but its StartPoint, etc stay the same. To get the "transformed" value, you will have to parse your XML, detect that a transform is applied, and modify the values by yourself... not so easy IMHO. – Antoine Jeanrichard Feb 29 '12 at 12:12

0 Answers0