I have this code that display a rectangle on a canvas :
XAML :
<Window x:Class="rotateRect.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:rotateRect"
mc:Ignorable="d"
Title="MainWindow" Height="402.027" Width="600.676">
<Grid>
<Canvas Name="my_c" HorizontalAlignment="Left" Height="24" Margin="160,149,0,0" VerticalAlignment="Top" Width="177" RenderTransformOrigin="0.5,0.5">
<Canvas.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform Angle="-68.962"/>
<TranslateTransform/>
</TransformGroup>
</Canvas.RenderTransform>
</Canvas>
</Grid>
I can turn it in XAML with "RenderTransform". But i wanted to implement this rotation in c# and create a "propeller". I tried to find information about "RotateTransform" for a canvas. Thys is my c# code :
C# :
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
namespace rotateRect
{
public partial class MainWindow : Window
{
Rectangle my_r = new Rectangle();
public MainWindow()
{
InitializeComponent();
initializeRect(my_r, my_c);
}
private void initializeRect(Rectangle r, Canvas c)
{
// rectangle
r.Width = 10;
r.Height = 50;
// rectangle Color
r.Fill = new SolidColorBrush(Color.FromRgb(0, 0, 255));
// canvas
c.Children.Add(r);
c.Width = 10;
c.Height = 50;
}
}
}
I found an exemple of "RotateTransform" for a bitmap object but i hadn't find anything for a canvas. C#, rotating Graphics?
It's possible to apply a RotateTransform to a canvas in c#?