1

I have a custom shape in WPF that creates two rectangles in the DefiningGeometry override and returns both as a GeometryGroup as follows:

protected override System.Windows.Media.Geometry DefiningGeometry
{
    get
    {
        System.Windows.Media.GeometryGroup group = null;
        System.Windows.Media.RectangleGeometry rectangle = null;

        group = new System.Windows.Media.GeometryGroup();

        if (this.Rectangle.IsEmpty)
        {
            group.Children.Add(System.Windows.Media.Geometry.Empty);
        }
        else
        {
            rectangle = new System.Windows.Media.RectangleGeometry(new System.Windows.Rect(this.Width * 0.1, this.Height - (this.Height * 0.1), this.Width * 0.8, this.Height * 0.1), 10, this.Height * 0.1);
            group.Children.Add(rectangle);

            rectangle = new System.Windows.Media.RectangleGeometry(new System.Windows.Rect(this.Width * 0.1, this.Height - (this.Height * 0.1), this.Width * 0.8, this.Height * 0.1), 10, this.Height * 0.1);
            rectangle.Transform = new System.Windows.Media.RotateTransform(this.Tilt, this.Width / 2D, this.Height / 2D);
            group.Children.Add(rectangle);
        }

        return (group);
    }
}

The problem is I only want to apply a transform on the second rectangle but when I do that as illustrated above, it transforms other geometries in the group as well.

This is supposed to represent an animation with one static bar and one rotating (thus the transform). Any advice would be helpful.

UPDATE: I was wrong about the rotation transformation happening on both rectangles. Rotation is only happening on one. But due to that rotation, the canvas seems to translate due to which the first rectangle also moves (without rotating through). any idea what's going on here?

Here is an animated GIF. Wait for both sliders to go up and down on at a time.

Animated Gif

The only thing changing here is the value of this.Tilt from -45 to +45 degrees.

Raheel Khan
  • 14,205
  • 13
  • 80
  • 168
  • @eranotzap: `RenderTransform` is not a property of the `RectangleGeometry` object. It does exist in the `Shape` itself but I don't see how that would help. – Raheel Khan Nov 10 '13 at 14:08
  • "But due to that rotation, the canvas seems to translate due to which the first rectangle also moves". What Canvas? How exactly does it "seem to translate"? Please provide more details. – Clemens Nov 10 '13 at 15:01
  • @Clemens: I have updated the question with a an animated GIF of what if happening with both the still and rotating rectangles. – Raheel Khan Nov 10 '13 at 15:26
  • Are you keeping the `Width` and `Height` values constant or do they somehow change? And still you haven't said how a Canvas is involved. Is your custom Shape placed on that Canvas? – Clemens Nov 10 '13 at 15:52
  • @Clemens: The Width and Height are not being changed at all. There is no canvas. What I meant by that was the surface the first rectangle is drawn on, "seems" to be translating but not rotating. Whereas the second rectangle is going though both types of transformations. – Raheel Khan Nov 10 '13 at 16:03

0 Answers0