具有DataTrigger和安全功能的PasswordBox

时间:2019-06-24 10:25:13

标签: c# wpf xaml

如果在passwordBox中绑定datatrigger的值是正确的

 <DataTrigger Binding="{Binding ElementName=password, Path=Password}" Value="">
     <Setter Property="IsEnabled" Value="false" />
 </DataTrigger>

PasswordBox字段

 <PasswordBox x:Name="password" PasswordChanged="Password_PasswordChanged" Style="{StaticResource passwordStyle}" />

和样式资源

<Style TargetType="PasswordBox" x:Key="passwordStyle">
        <Setter Property="Width" Value="190"/>
        <Setter Property="Height" Value="30"/>
        <Setter Property="FontSize" Value="20"/>
        <Setter Property="Padding" Value="6,1,1,0"/>

        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type PasswordBox}">
                    <Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" 
                                BorderThickness="{TemplateBinding BorderThickness}" 
                                Background="{TemplateBinding Background}" 
                                CornerRadius="10"
                                SnapsToDevicePixels="True">
                        <ScrollViewer x:Name="PART_ContentHost" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

我通过界面发送密码而未绑定到ViewModel,因为它不会保留存储在内存中的密码

对于passwordbox,如果第一个应用程序启动时该字段为空,则我需要阻止按钮,因为事件PasswordChanged不会这样做。

但是如果我绑定了触发器,它会破坏这种逻辑吗?

是否正确?如果考虑一下内存。

0 个答案:

没有答案
相关问题