[不是问题] WPF按钮可见性在一段时间后发生变化 [英] [Not a question] WPF button visibility change after certain time of period

查看:237
本文介绍了[不是问题] WPF按钮可见性在一段时间后发生变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我是wpf的新手。我有代码,我想在某段时间内显示按钮,然后改变他的可见性。



这是我的代码



故事板sb = 故事板(); 
ObjectAnimationUsingKeyFrames objAn = new ObjectAnimationUsingKeyFrames();
objAn.BeginTime = TimeSpan.FromSeconds( 0 );
Storyboard.SetTarget(objAn,dock);
Storyboard.SetTargetProperty(objAn, new PropertyPath(UIElement.VisibilityProperty));
DiscreteObjectKeyFrame objd = new DiscreteObjectKeyFrame(Visibility.Visible,KeyTime.FromTimeSpan(TimeSpan.FromSeconds( 0 )));
objAn.KeyFrames.Add(objd);
DiscreteObjectKeyFrame objd1 = new DiscreteObjectKeyFrame(Visibility.Hidden,KeyTime.FromTimeSpan(TimeSpan.FromSeconds( 2 )));
objAn.KeyFrames.Add(objd1);
sb.Children.Add(objAn);
sb.BeginAnimation(UIElement.VisibilityProperty,objAn);





dock 是我的按钮名称



等待回复。

解决方案

它更容易控制xaml代码中的动画,其中你的故事板在那里撒谎而不是创建故事板代码隐藏。 。

Hi,
I am new in wpf. I have code in which I want to show button for certain time of period and then change his visibilty.

Here is my code

Storyboard sb = new Storyboard();
           ObjectAnimationUsingKeyFrames objAn = new ObjectAnimationUsingKeyFrames();
           objAn.BeginTime = TimeSpan.FromSeconds(0);
           Storyboard.SetTarget(objAn, dock);
           Storyboard.SetTargetProperty(objAn, new PropertyPath(UIElement.VisibilityProperty));
           DiscreteObjectKeyFrame objd = new DiscreteObjectKeyFrame(Visibility.Visible, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)));
           objAn.KeyFrames.Add(objd);
           DiscreteObjectKeyFrame objd1 = new DiscreteObjectKeyFrame(Visibility.Hidden, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2)));
           objAn.KeyFrames.Add(objd1);
           sb.Children.Add(objAn);
           sb.BeginAnimation(UIElement.VisibilityProperty, objAn);



dock is my button name

Waiting for reply.

解决方案

its easier to control animation in xaml code where your storyboard lied there rather than creating storyboard in codebehind. . .


这篇关于[不是问题] WPF按钮可见性在一段时间后发生变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆