Tag: storyboard

自动平滑resize过渡 – 故事板的问题

我已经尝试了一段时间来创建一个类/系列类,在检测到相关对象中的resize时,尝试暂停对象的大小调整并为其创建平滑的resize动画。 但是,在动画开始播放之前,我一直遇到屏幕上对象“闪烁”一秒的问题。 长话短说,经过一些严肃的调试和自我怀疑,我的印象是调用Storyboard.Begin()不会影响目标值,直到下一个时钟滴答 。 我认为这与Storyboard.Seek()直到下一个时钟滴答时才会发生。 ( 请参阅MSDN参考 )。 因此,在动画开始之前,对象在单个帧中采用其新高度,将其拉回到起始高度。 我花了很长时间试图让它工作,因为它不像看起来那么简单。 我无法将FrameworkElement.Height设置为FrameworkElement.SizeChanged事件处理程序中的e.PreviousSize.Height ,因为它会影响对象的“true”高度。 作为为什么这不起作用的一个例子,如果在播放动画时某些东西改变了对象的“真实”高度,那么将FrameworkElement.Height重新设置为动画开始时收集的目标高度可以设置它作为一个不正确的,过时的价值。 还有更多我尝试过的东西,我相信它们会在答案到来时出现,但是你们的任何想法都会非常感激。

故事板完成后如何调用方法?

我写下面的代码: public void name(object sender, RoutedEventArgs e) { DoubleAnimation myDoubleAnimation = new DoubleAnimation(); myDoubleAnimation.From = 1.0; myDoubleAnimation.To = 0.0; myDoubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.2)); sb1 = new Storyboard(); sb1.Children.Add(myDoubleAnimation); Storyboard.SetTargetName(myDoubleAnimation, one.Name); Storyboard.SetTargetProperty(myDoubleAnimation, new PropertyPath(Grid.OpacityProperty)); sb1.Begin(this); if (one.Opacity == 0) { Container_one.Children.Remove(one); } } 但它没有正确的做法。 动画工作正常,但删除错误。 如何将Storyboard-End与对方法的调用结合起来? 很多东西。

在可见性更改时激活故事板

目前我有一个Image ,它在加载时会发出脉冲。 当我改变图像的可见性时,我想要激活故事板。 但是我看到Image.Triggers必须是EventTriggers 。 我需要加入哪个事件?

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

我正在尝试使用代码隐藏中的StoryBoard同时为Rectangle的TranslateTransform和ScaleTransform设置动画。 我研究了一些类似的问题,但我有些问题,我仍然坚持第一步。 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 = […]

StoryBoard – 从代码隐藏中设置目标名称

我有资源中的StoryBoard 在WindowClosing上我有下一个代码 private void NotifyWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) { Storyboard fading = this.Resources[“Fading”] as Storyboard; if (fading != null && !fadingCompleted) { fading.Completed += FadingStoryBoard_Completed; fading.Begin(); e.Cancel = true; } } private void FadingStoryBoard_Completed(object sender, EventArgs e) { fadingCompleted = true; Close(); fadingCompleted = false; } 这工作正常,但我想将这个故事板移动到另一个组件。 所以我需要指定StoryBoard.TargetName表单代码。 我怎样才能做到这一点?

System.Windows.Media.Animation警告:6

当我使用故事板在wpf中运行动画时,我在输出窗口中出现以下错误。 System.Windows.Media.Animation警告:6:无法执行操作,因为指定的Storyboard从未应用于此对象以进行交互式控制。 行动=“停止”; 故事板= ‘System.Windows.Media.Animation.Storyboard’; Storyboard.HashCode = ‘57850459’; Storyboard.Type = ‘System.Windows.Media.Animation.Storyboard’; TargetElement = ‘System.Windows.Media.Animation.Storyboard’; TargetElement.HashCode = ‘57850459’; TargetElement.Type = ‘System.Windows.Media.Animation.Storyboard’ 谁能告诉我它将如何影响我的程序以及如何删除它? 我没有在.xaml文件中定义storyboard。 但是当设计文件(.xaml)背后的代码我在类中创建了私有stoaryboard时,我使用代码中的以下语法将其分配给framework元素。 this.storyboard1.Begin(this.viewbox1, true); storyboard1是我在类中创建的对象,viewbox1是我要应用此动画的元素。 有谁能够帮我? 提前致谢。

SetTarget vs RegisterName / SetTargetName

这是一个简单的程序,可以为Line的Y2属性设置动画。 请注意,我使用SetTarget方法来定位Line 。 这个程序工作正常。 using System; using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; namespace SoGeneratingAnimatedLine { public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); var canvas = new Canvas(); Content = canvas; var sb = new Storyboard(); var line = new Line() { X1 = 10, Y1 = 10, […]

在’System.Windows.Controls.Button’的名称范围内找不到名称

我的Button有以下Template … … 问题是Storyboard.TargetName=”col1″ col1没有拾取Storyboard.TargetName=”col1″ 。 我收到错误: An unhandled exception of type ‘System.InvalidOperationException’ occurred in PresentationFramework.dll Additional information: ‘col1’ name cannot be found in the name scope of ‘System.Windows.Controls.Button’. 我认为这可能与我正在使用Items Control这一事实有关…我认为col1会被尝试在任何包含元素中找到。 我不知道如何解决这个问题。 任何帮助将不胜感激!

WPF StoryBoard.Completed事件未触发

关闭主窗口之前我有一个动画,如下面的代码所示。 问题是StoryBoard.Completed没有触发。 是什么原因引起了这个? 码 DoubleAnimation dblAnimX = new DoubleAnimation(1.0, 0.0, new Duration(TimeSpan.FromSeconds(0.5))); dblAnimX.SetValue(Storyboard.TargetProperty, this); DoubleAnimation dblAnimY = new DoubleAnimation(1.0, 0.0, new Duration(TimeSpan.FromSeconds(0.5))); dblAnimY.SetValue(Storyboard.TargetProperty, this); Storyboard story = new Storyboard(); Storyboard.SetTarget(dblAnimX, this); Storyboard.SetTarget(dblAnimY, this); Storyboard.SetTargetProperty(dblAnimX, new PropertyPath(“RenderTransform.ScaleX”)); Storyboard.SetTargetProperty(dblAnimY, new PropertyPath(“RenderTransform.ScaleY”)); story.Children.Add(dblAnimX); story.Children.Add(dblAnimY); story.Begin(this); story.Completed += (o, s) => { this.Close(); };

Storyboard.SetTarget与Storyboard.SetTargetName

为什么Storyboard.SetTargetName有效,但Storyboard.SetTarget却没有? 在这里xaml – 在这里C# private void smartContent_ContentChanging(object sender, RoutedEventArgs e) { Storyboard storyBoard = new Storyboard(); DoubleAnimation doubleAnimation1 = new DoubleAnimation(0.0, -smartContent.RenderSize.Width, new Duration(new TimeSpan(0, 0, 0, 0, 500))); DoubleAnimation doubleAnimation2 = new DoubleAnimation(smartContent.RenderSize.Width, 0.0, new Duration(new TimeSpan(0, 0, 0, 0, 500))); doubleAnimation1.AccelerationRatio = 0.5; doubleAnimation2.DecelerationRatio = 0.5; storyBoard.Children.Add(doubleAnimation1); storyBoard.Children.Add(doubleAnimation2); Storyboard.SetTarget(doubleAnimation1, this.translateTransformLast); //— this does […]