我想在wpf窗口中闪烁标签内容,怎么做? [英] I want blinking label content in wpf window, how to do it?
本文介绍了我想在wpf窗口中闪烁标签内容,怎么做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想向用户显示错误消息,但错误应以闪烁方式显示
我不知道如何在wpf中执行此操作。
所以请帮助我。
谢谢
sushil
我尝试了什么:
我试过TextDecoration属性,但它不在wpf中。我不知道。
解决方案
您是否考虑使用动画来控制闪烁的消息?举个例子,我只是向XAML添加了一个按钮和一个文本块。然后为按钮创建了一个点击事件。
< Grid>
<按钮x:名称= 按钮内容= 按钮 HorizontalAlignment = 左 VerticalAlignment = Top Width = 75 Click = button_Click跨度> />
< TextBlock x:Name = textBlock HorizontalAlignment = 左 TextWrapping = 换行 Text = 警告 VerticalAlignment = Top Margin = 0,26,0,0\" 跨度> />
< / 网格 >
然后将以下内容添加到我的主窗口。
public partial 类 MainWindow:Window
{
DoubleAnimation da = new DoubleAnimation();
public MainWindow()
{
InitializeComponent();
da.From = 30 ;
da.To = 35 ;
da.AutoReverse = true ;
da.RepeatBehavior = new RepeatBehavior( 3 );
da.Duration = new 持续时间(TimeSpan.FromSeconds( 0 。 5 跨度>));
}
private void button_Click(< span class =code-keyword> object sender,RoutedEventArgs e)
{
textBlock.BeginAnimation(TextBlock.FontSizeProperty,da);
}
}
这个
在资源中声明这个StoryBoard
< storyboard x:key = FlashMe
< span class =code-attribute> RepeatBehavior = 永远 >
< objectanimationusingkeyframes storyboard.targetproperty = (UIElement.Visibility ) >
< 离散objectkeyframe keytime = 0:0:0.5 >
< discreteobjectkeyframe.value >
< 可见性 > 折叠< / visibility >
< / discreteobjectkeyframe.value >
< / discreteobjectkeyframe >
< discreteobjectkeyframe keytime = 0:0:1 >
< < span class =code-leadattribute> discreteobjectkeyframe.value >
< 可见性 > 可见< / visibility >
< / discreteobjectkeyframe.value >
< / discreteobjectkeyframe >
< / objectanimationusingkeyframes >
< / storyboard >
&在你的ButtonClickEvent
写
textBox.BeginStoryboard(FindResource(FlashMe)作为故事板);
I want to show error Message to user, but error should display in blinking manner
I don't know how to do it in wpf.
so please help me.
thank you
sushil
What I have tried:
I tried TextDecoration property but it is not in wpf may be. i dont know.
解决方案
Have you considered using a animation to control the blinking message ? For an example I have simply added a button and a textblock to XAML. Then created a click event for the button.
<Grid> <Button x:Name="button" Content="Button" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Click="button_Click"/> <TextBlock x:Name="textBlock" HorizontalAlignment="Left" TextWrapping="Wrap" Text="Warning" VerticalAlignment="Top" Margin="0,26,0,0"/> </Grid>
And then add the following to my main windows.
public partial class MainWindow : Window { DoubleAnimation da = new DoubleAnimation(); public MainWindow() { InitializeComponent(); da.From = 30; da.To = 35; da.AutoReverse = true; da.RepeatBehavior = new RepeatBehavior(3); da.Duration = new Duration(TimeSpan.FromSeconds(0.5)); } private void button_Click(object sender, RoutedEventArgs e) { textBlock.BeginAnimation(TextBlock.FontSizeProperty, da); } }
This
Declare This StoryBoard in Resources
<storyboard x:key="FlashMe" RepeatBehavior="Forever"> <objectanimationusingkeyframes storyboard.targetproperty="(UIElement.Visibility)"> <discreteobjectkeyframe keytime="0:0:0.5"> <discreteobjectkeyframe.value> <visibility>Collapsed</visibility> </discreteobjectkeyframe.value> </discreteobjectkeyframe> <discreteobjectkeyframe keytime="0:0:1"> <discreteobjectkeyframe.value> <visibility>Visible</visibility> </discreteobjectkeyframe.value> </discreteobjectkeyframe> </objectanimationusingkeyframes> </storyboard>
& in Your ButtonClickEvent
write
textBox.BeginStoryboard(FindResource("FlashMe") as Storyboard);
这篇关于我想在wpf窗口中闪烁标签内容,怎么做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文