WPF Inkcanvas绘制和旋转形状

时间:2016-05-16 09:37:59

标签: wpf

我想知道如何在wpf中旋转和移动在inkcanvas上绘制的形状。我正在使用VS 2015并开发一个名为WhiteBoard的项目。在那块板子上我使用的是Inkcanvas,它用于绘制和擦除圆形,矩形等形状。

提前致谢。

1 个答案:

答案 0 :(得分:0)

您可以旋转或移动整个InkCanvas。检查一下:

<Window.Resources>
        <Storyboard x:Key="RotateTransformStoryboard">
            <DoubleAnimation Storyboard.TargetName="inkCanvas" From="0" To="359" BeginTime="00:00:00" Duration="00:00:05"
                             RepeatBehavior="1" 
                             Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(RotateTransform.Angle)" >
            </DoubleAnimation>

        </Storyboard>
    </Window.Resources>
    <Window.Triggers>
        <EventTrigger RoutedEvent="Button.Click">
            <BeginStoryboard Storyboard="{StaticResource RotateTransformStoryboard}"/>
        </EventTrigger>
    </Window.Triggers>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>


        <InkCanvas Grid.Row="0" x:Name="inkCanvas" RenderTransformOrigin="0.5,0.5">
            <InkCanvas.RenderTransform>
                <TransformGroup>
                    <RotateTransform Angle="0" />
                </TransformGroup>
            </InkCanvas.RenderTransform>      
        </InkCanvas>
        <Button x:Name="btn1" Content="transform" Grid.Row="1" Height="30" />
    </Grid>