如何在WPF 4.0中创建发光的TextBox?

编程入门 行业动态 更新时间:2024-10-26 00:21:01
本文介绍了如何在WPF 4.0中创建发光的TextBox?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试创建一个文本框,该文本框在聚焦时会发光。

I'm trying to create a text box, which would glow when focused.

到目前为止,我所见过的所有示例均基于 OuterGlowBitmapEffect ,它似乎在 4中不起作用。

All samples of how to do this I've seen so far were based on OuterGlowBitmapEffect , and it appears that it does not work in 4.

第二篇文章中的建议是使用模糊效果。我不知道如何使用模糊来使对象的外层发光而不扭曲对象的内部内容。

The recommendation in the second article is to use blur effect. I have no idea on how to use blur to get object's outer layer to glow without distorting the inner content of the object.

最终,我希望创建一个文本框,当聚焦时将显示发光的动画,并且在控件失去焦点后发光将缓慢(1-2秒)消失。

Ultimately, I'm hoping to create a text box, which would display glow up animation when focused, and the glow would slowly (1-2 seconds) fade after the control has lost focus.

关于什么是任何想法在wpf 4.0中执行此操作的最佳方法?

Any ideas on what is the best way to do this in wpf 4.0?

推荐答案

您可以尝试使用 DropShadowEffect 。这是一个示例

You can try to get a decent "Glow-Effect" with DropShadowEffect. Here is an example

更新。 TextBox 在聚焦时开始发光,而在失去聚焦时发光缓慢消失两秒钟

Update. A TextBox that starts to "glow" when focused and the "glow" slowly fades out for two seconds when it loses focus

<TextBox Text="Test"> <TextBox.Style> <Style TargetType="TextBox"> <Setter Property="Effect"> <Setter.Value> <DropShadowEffect ShadowDepth="0" Color="Gold" Opacity="0" BlurRadius="8"/> </Setter.Value> </Setter> <Style.Triggers> <Trigger Property="IsFocused" Value="True"> <Trigger.EnterActions> <BeginStoryboard> <Storyboard> <DoubleAnimation To="1.0" Storyboard.TargetProperty="(Effect).Opacity" Duration="00:00:00"/> </Storyboard> </BeginStoryboard> </Trigger.EnterActions> <Trigger.ExitActions> <BeginStoryboard> <Storyboard> <DoubleAnimation To="0.0" Storyboard.TargetProperty="(Effect).Opacity" Duration="00:00:02"/> </Storyboard> </BeginStoryboard> </Trigger.ExitActions> </Trigger> </Style.Triggers> </Style> </TextBox.Style> </TextBox>

更多推荐

如何在WPF 4.0中创建发光的TextBox?

本文发布于:2023-11-12 05:08:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1580595.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   WPF   TextBox

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!