首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WPF使用故事板放大矩形

WPF使用故事板放大矩形
EN

Stack Overflow用户
提问于 2015-08-02 05:03:22
回答 1查看 53关注 0票数 0

你好,我有一个Window>grid>rectangle,名为as (rect1)

我怎么用故事板放大这个?

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

代码语言:javascript
复制
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();



    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-02 06:06:22

您应该将宽度和高度属性动画如下:

代码语言:javascript
复制
        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();
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31768739

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档