无法在c#按钮单击时停止动画旋转 [英] unable to stop the animation rotation on button click in c#

查看:71
本文介绍了无法在c#按钮单击时停止动画旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <  窗口    x:Class   =  rotat .MainWindow  

< span class =code-attribute> xmlns = http:// schemas.microsoft.com/winfx/2006/xaml/presentation\"

< span class =code-attribute> xmlns:x = http://schemas.microsoft.com/winfx/2006/xaml

标题 = MainWindow < span class =code-attribute>高度 = 350 宽度 = 525 >

< Window.Resources >
< 故事板 x:键 = sbdRotation RepeatBehavior = 永远 >
< DoubleAnimation

Storyboard。 TargetName = image

Storyboard.TargetProperty = (Image.LayoutTransform)。(RotateTransform.Angle)

来自 = 0 = 360 持续时间 = 0:0:0:1 FillBehavior = 停止 / >
< / Storyboard >

< / Window.Resources >

< 网格 >
< Grid.RowDefinitions >
< RowDefinition / >
< RowDefinition / >
< /Grid.RowDefinitions>

< 图像 名称 = image 宽度 = 50 高度 = 50 来源 = C:\ Users\shreddy.FAREAST \Pictures\disk1.png >
< 图片。 LayoutTransform >
< RotateTransform CenterX = 0.5 CenterY = 0.5 / >
< / Image.LayoutTransform >
< / Image >

< 按钮 Grid.Row = 1 内容 = 旋转图像! 点击 = Button_Click 宽度 = 100 高度 = 100 保证金 < span class =code-keyword> =
106,30,311,29 < span class =code-keyword> / >
< 按钮 x:名称 = 停止 宽度 = 100 高度 = 100 保证金 = 308,20,109,39 Grid.Row = 1 单击 = stop_Click 内容 = 停止 / >
< / Grid >
< / Window >







和我的c#代码



 < span class =code-keyword> public  MainWindow()
{
InitializeComponent();
sd = new Storyboard();
sd =(故事板)FindResource( sbdRotation);
}
public void Button_Click( object sender,RoutedEventArgs args)
{

// while(mn> 0)
// {

sd.Begin( this );
mn--;
d ++;
// }
}

private void stop_Click( object sender,RoutedEventArgs e)
{
sd.Stop( this );
}





但是无法停止轮换

解决方案

< blockquote>你好Shalini,



请在开始你的故事板时使用这段代码,



 sd.Begin(this,true); 





这里的第二个参数是可控的。因此,你可以控制你的动画..



更多信息 -



http://msdn.microsoft。 com / en-us / library / system.windows.media.animation.storyboard.aspx [ ^ ]





Hope这会对你有帮助..


<Window x:Class="rotat.MainWindow"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        Title="MainWindow" Height="350" Width="525">

    <Window.Resources>
        <Storyboard x:Key="sbdRotation"  RepeatBehavior="Forever">
            <DoubleAnimation

            Storyboard.TargetName="image"

            Storyboard.TargetProperty="(Image.LayoutTransform).(RotateTransform.Angle)"

            From="0" To="360"   Duration="0:0:0:1" FillBehavior="Stop"/>
        </Storyboard>

    </Window.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition />
        </Grid.RowDefinitions>

        <Image Name="image" Width="50" Height="50" Source="C:\Users\shreddy.FAREAST\Pictures\disk1.png">
            <Image.LayoutTransform>
                <RotateTransform CenterX="0.5" CenterY="0.5" />
            </Image.LayoutTransform>
        </Image>

        <Button Grid.Row="1" Content="Rotate the image!" Click="Button_Click" Width="100" Height="100" Margin="106,30,311,29" />
        <Button x:Name="stop" Width="100" Height="100" Margin="308,20,109,39" Grid.Row="1" Click="stop_Click" Content="stop"/>
    </Grid>
</Window>




and my c# code

public MainWindow()
     {
         InitializeComponent();
         sd = new Storyboard();
         sd = (Storyboard)FindResource("sbdRotation");
     }
     public void Button_Click(object sender, RoutedEventArgs args)
     {

         //while (mn>0)
         //{

             sd.Begin(this);
             mn--;
             d++;
        // }
     }

     private void stop_Click(object sender, RoutedEventArgs e)
     {
         sd.Stop(this);
     }



But not able to stop the rotation

解决方案

Hello Shalini,

Please use this code while you Begin your storyboard,

sd.Begin(this,true);



Here second argument is controllable. Due to this you can control to your animation..

For more information -

http://msdn.microsoft.com/en-us/library/system.windows.media.animation.storyboard.aspx[^]


Hope this will help you..


这篇关于无法在c#按钮单击时停止动画旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆