Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在ResourceDictionary中使用ControlTemplate自定义Passwordbox后,密码属性为空_C#_Wpf_Controltemplate_Resourcedictionary_Passwordbox - Fatal编程技术网

C# 在ResourceDictionary中使用ControlTemplate自定义Passwordbox后,密码属性为空

C# 在ResourceDictionary中使用ControlTemplate自定义Passwordbox后,密码属性为空,c#,wpf,controltemplate,resourcedictionary,passwordbox,C#,Wpf,Controltemplate,Resourcedictionary,Passwordbox,我已经通过ResourceDictionary定制了我的项目文本框 <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" > <Style x:Key="TextBoxTh

我已经通过ResourceDictionary定制了我的项目文本框

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
<Style x:Key="TextBoxTheme" TargetType="{x:Type TextBox}">
    <Style.Setters>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="TextBox">
                    <Border CornerRadius="10" 
                            BorderBrush="{TemplateBinding BorderBrush}" 
                            BorderThickness="2" 
                            Background="#FF62B6CB">
                        <Grid>
                            <TextBox VerticalContentAlignment="Center" 
                                     HorizontalContentAlignment="Left" 
                                     Padding="5,0,5,0" 
                                     Background="Transparent" 
                                     BorderThickness="0"
                                     Foreground="#1B4965"
                                     Margin="1"
                                     TextWrapping="Wrap"
                                     FontWeight="Bold"
                                     Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Text, UpdateSourceTrigger=PropertyChanged}"/>
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="TextWrapping" Value="Wrap" />
    </Style.Setters>
</Style>

现在我正在尝试向密码箱添加相同的设计

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
<Style x:Key="PasswordBoxTheme" TargetType="{x:Type PasswordBox}">
    <Style.Setters>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="PasswordBox">
                    <Border CornerRadius="10" 
                            BorderBrush="{TemplateBinding BorderBrush}" 
                            BorderThickness="2" 
                            Background="#FF62B6CB">
                        <Grid>
                            <PasswordBox VerticalContentAlignment="Center" 
                                         HorizontalContentAlignment="Left" 
                                         Padding="5,0,5,0" 
                                         Background="Transparent" 
                                         BorderThickness="0"
                                         Foreground="#1B4965"
                                         Margin="1"
                                         FontWeight="Bold" />
                                         <!--Password="{Binding RelativeSource= {RelativeSource TemplatedParent}, Path=Password, UpdateSourceTrigger=PropertyChanged}"/-->
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style.Setters>
</Style>


我遇到的问题是,即使我输入了密码,Passwordbox的Password属性也是空的。如何访问密码?

WPF实际上在内部并不绑定到
密码框的
密码
属性,而是始终绑定到名为“属性”的
从属属性。如果您查看
PasswordBox
类,就会发现一些依赖属性

例如:
公共静态只读从属属性CaretBrushProperty

但是你找不到一个
公共静态只读DependencyProperty PasswordProperty
WPF可以绑定到的位置

长话短说:密码不可绑定