[英]WPF enlarge a rectangle using storyboard
嗨,我有一個窗口>網格>矩形,名為(rect1)
我如何使用情節提要放大
錯誤:其他信息:不存在適用的名稱范圍來解析名稱“ 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();
}
您應該像這樣設置width和height屬性的動畫:
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();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.