【问题标题】:WPF enlarge a rectangle using storyboardWPF使用情节提要放大矩形
【发布时间】:2015-08-02 14:23:18
【问题描述】:

您好,我有一个名为 (rect1) 的 Window>grid>矩形

如何使用情节提要放大此内容

错误:附加信息:不存在可解析名称“rect1”的适用名称范围

private void Window_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
    {

        Storyboard buttonEnlargeStoryboard = new Storyboard();
        DoubleAnimation da = new DoubleAnimation();
        da.SetValue(Storyboard.TargetNameProperty, rect1.Name);
        da.BeginTime = new TimeSpan(0);
        da.Duration = TimeSpan.FromSeconds(1);
        buttonEnlargeStoryboard.Children.Add(da);

        buttonEnlargeStoryboard.Begin();



    }

【问题讨论】:

    标签: c# wpf storyboard


    【解决方案1】:

    您应该像这样为宽度和高度属性设置动画:

            DoubleAnimation widthAnimation = new DoubleAnimation
            {
                From = 0,
                To = rect1.ActualWidth*2,
                Duration = TimeSpan.FromSeconds(5)
            };
    
            DoubleAnimation heightAnimation = new DoubleAnimation
            {
                From = 0,
                To = rect1.ActualHeight*2,
                Duration = TimeSpan.FromSeconds(5)
            };
    
            Storyboard.SetTargetProperty(widthAnimation, new PropertyPath(Rectangle.WidthProperty));
            Storyboard.SetTarget(widthAnimation, rect1);
    
            Storyboard.SetTargetProperty(heightAnimation, new PropertyPath(Rectangle.HeightProperty));
            Storyboard.SetTarget(heightAnimation, rect1);
    
            Storyboard buttonEnlargeStoryboard = new Storyboard();
            buttonEnlargeStoryboard.SpeedRatio = 1;
            buttonEnlargeStoryboard.Children.Add(widthAnimation);
            buttonEnlargeStoryboard.Children.Add(heightAnimation);
            buttonEnlargeStoryboard.Begin();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-04
      • 1970-01-01
      • 2010-11-30
      • 2020-11-30
      • 2011-01-16
      • 1970-01-01
      • 2015-02-14
      相关资源
      最近更新 更多