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.
The only thing changing here is the value of this.Tilt
from -45 to +45 degrees.