标签: doubleanimation

如何在WPF中为TranslateTransform和ScaleTransform设置动画

我正在尝试使用代码隐藏同时为a TranslateTransformScaleTransforma 设置动画.我研究了一些类似的问题,但我有些问题,我仍然坚持第一步.RectangleStoryBoard

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <Rectangle x:Name="MyRectangle" Width="100" Height="100" Fill="Aqua"></Rectangle>
    <Button Grid.Row="1" Content="Animate" Click="ButtonBase_OnClick"/>
</Grid>

    private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
    {
        var translate_x = new DoubleAnimation()
        {
            From = 0,
            To = 100,
            Duration = TimeSpan.FromSeconds(5),
        };
        var translate_y = new DoubleAnimation()
        {
            From = 0,
            To = 100,
            Duration = TimeSpan.FromSeconds(5),
        };

        var scale_x = new DoubleAnimation()
        {
            From = 1,
            To = 2,
            Duration = TimeSpan.FromSeconds(5),
        }; …
Run Code Online (Sandbox Code Playgroud)

c# wpf storyboard doubleanimation

4
推荐指数
1
解决办法
6013
查看次数

使用DoubleAnimation设置图像不透明度

这应该是相当简单的,但我似乎无法做到正确.我有一个集合System.Windows.Controls.Image.当我选择其中一个时,我希望所有其他人都能获得不透明度0.5.我正在使用MVVM,这背后的逻辑(找到所选图像并将其设置为Enabled)已完成ViewModel,并且正在运行.所以基本上这是有效的:

<Image Grid.Row="0" Source="{Binding ItemImage}" IsEnabled="{Binding ItemImageEnabled}">
<Image.Style>
    <Style TargetType="Image">
        <Style.Triggers>
            <Trigger Property="IsEnabled"  Value="False">
                <Setter Property="Opacity" Value="0.5"/>
            </Trigger>
            <Trigger Property="IsEnabled" Value="True">
                <Setter Property="Opacity" Value="1.0"/>
            </Trigger>
        </Style.Triggers>
    </Style>
</Image.Style>
</Image>
Run Code Online (Sandbox Code Playgroud)

现在我想的不透明度转变到进行动画,从衰落它1.00.5当没有选择图像,和从衰落0.51.0当它.我会想到这会工作:

<Image Grid.Row="0" Source="{Binding ItemImage}" IsEnabled="{Binding ItemImageEnabled}">
<Image.Style>
    <Style TargetType="Image">
        <Style.Triggers>
            <Trigger Property="IsEnabled"  Value="False">
                <Trigger.EnterActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetProperty="Opacity" From="1" To="0.5" BeginTime="0:0:0" Duration="0:0:1"/>
                        </Storyboard>
                    </BeginStoryboard>
                </Trigger.EnterActions>
            </Trigger>
            <Trigger Property="IsEnabled" Value="True">
                <Trigger.EnterActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetProperty="Opacity" …
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml mvvm doubleanimation

2
推荐指数
1
解决办法
390
查看次数

如何在wpf中创建两个动画之间的时间延迟

我是 WPF 新手,我只想为两个对象一个接一个地制作动画。这意味着第二个动画应该在第一个动画完成后开始。我尝试使用计时器和睡眠方法,但效果不佳。下面是示例代码:

DoubleAnimation da1 = new DoubleAnimation()
{

   From = 10,
   To = 200,
   Duration = new System.Windows.Duration(TimeSpan.FromSeconds(sec)),
};


temLabel1.BeginAnimation(Canvas.TopProperty, da1);
Delay(); // Delay when busy

DoubleAnimation da2 = new DoubleAnimation()
{

   From = 300,
   To = 500,
   Duration = new System.Windows.Duration(TimeSpan.FromSeconds(sec)),
};

ItemLabels2.BeginAnimation(Canvas.LeftProperty, da2);
Run Code Online (Sandbox Code Playgroud)

我用来Timer在两个动画之间创建时间延迟

 /* Setting Timer For delay during animation */

  timer.Interval = sec * 1000 + 50;
  timer.Elapsed += Timer_Elapsed;    
Run Code Online (Sandbox Code Playgroud)

延迟函数的代码是:

void Delay()
{
     busy = true;
     timer.Start();

     while (busy) {} …
Run Code Online (Sandbox Code Playgroud)

c# wpf animation doubleanimation

2
推荐指数
1
解决办法
2512
查看次数

无法停止故事板动画,我只能开始它

我正在尝试用故事板管理一个动画,它是一个闪烁的标签,并且实现了这个效果我已经使用了这个代码(动画我首选只在后面的代码中工作):我宣布我的故事板;

    public partial class Example: Page
    {
         public Storyboard LabelStoryboard=new Storyboard(); 
    }
Run Code Online (Sandbox Code Playgroud)

然后我发布动画:

 private void FlashWinLabel(){

        DoubleAnimation Flash= new DoubleAnimation();
        Flash.Duration = TimeSpan.FromMilliseconds(400);
        Flash.From = 1.0d;
        Flash.To = 0.0d;
        Flash.RepeatBehavior = RepeatBehavior.Forever;
        WinLabel.BeginAnimation(Label.OpacityProperty, Flash);

        SolidColorBrush myAnimatedBrush = new SolidColorBrush();
        myAnimatedBrush.Color = Colors.White;
        WinLabel.Foreground = myAnimatedBrush;


        this.RegisterName("MyAnimatedBrush", myAnimatedBrush);

        ColorAnimation LabelColorAnimation = new ColorAnimation();
        LabelColorAnimation.To = Colors.GreenYellow;
        LabelColorAnimation.Duration = TimeSpan.FromMilliseconds(200);
        LabelColorAnimation.RepeatBehavior = RepeatBehavior.Forever;
        LabelColorAnimation.AutoReverse = true;
        Storyboard.SetTargetName(LabelColorAnimation, "MyAnimatedBrush");
        Storyboard.SetTargetProperty(
            LabelColorAnimation, new PropertyPath(SolidColorBrush.ColorProperty));

        LabelStoryboard.Children.Add(LabelColorAnimation);

        WinLabel.BeginStoryboard(LabelStoryboard);


    }
Run Code Online (Sandbox Code Playgroud)

所有这一切都有效,直到这一点,当我试图通过按下屏幕上的按钮来停止故事板时出现问题:

     private void StopStoryBoard()
    {
        LabelStoryboard.Stop();

    } …
Run Code Online (Sandbox Code Playgroud)

c# wpf storyboard wpf-animation doubleanimation

1
推荐指数
1
解决办法
2801
查看次数

标签 统计

c# ×4

doubleanimation ×4

wpf ×4

storyboard ×2

animation ×1

mvvm ×1

wpf-animation ×1

xaml ×1