简体   繁体   English

WPF在文本框中模糊文本

[英]WPF Blur text in textbox

I want to set blur text in Textbox and PasswordBox. 我想在Textbox和PasswordBox中设置模糊文本。 When Textbox and PasswordBox is focused, that blur text will disappear and when lost focus, blur text will reappear. 当Textbox和PasswordBox聚焦时,该模糊文本将消失,当失去焦点时,模糊文本将重新出现。 Any solution? 有解决方案吗

You can use triggers to dynamically change value of a property under certain conditions. 您可以使用触发器在特定条件下动态更改属性的值。 In this case you can set Effect property value to BlurEffect when the control is focused like this: 在这种情况下,当控件聚焦时,您可以将Effect属性值设置为BlurEffect

<Style x:Key="BlurEffect" TargetType="{x:Type Control}">
    <Style.Triggers>
        <Trigger Property="IsFocused" Value="False">
            <Setter Property="Effect">
                <Setter.Value>
                    <BlurEffect Radius="5"></BlurEffect>
                </Setter.Value>
            </Setter>
        </Trigger>
    </Style.Triggers>
</Style>

Then you apply your style to you control: 然后你将你的风格应用到你的控制:

<TextBox Style="{StaticResource BlurEffect}" />
<PasswordBox Style="{StaticResource BlurEffect}" />

You can apply this style to any element derived from Control class. 您可以将此样式应用于从Control类派生的任何元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM