WPF PasswordBox中的光标位置怎么设置?

时间:2022-02-12 10:30:17
使用PasswordBox控件时,发现光标的位置偏上,不知道怎么调到居中,怎么弄? WPF PasswordBox中的光标位置怎么设置?

7 个解决方案

#1


附上xaml
                    <PasswordBox Height="36" Name="passwordBox" Margin="5" Padding="0">
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="PasswordChanged">
                                <i:InvokeCommandAction Command="{Binding SetPasswordCommand}"
                                                       CommandParameter="{Binding ElementName=passwordBox, Path=Password}"/>
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </PasswordBox>

#2



            <PasswordBox Height="36" Name="passwordBox" Margin="5" Padding="0" VerticalContentAlignment="Center">

#3


<PasswordBox Height="36" Name="passwordBox" Margin="5" Padding="0" VerticalContentAlignment="Center">

#4


呵呵,柳暗花明又一村啊,看了半天没看到,发完贴突然就找到了。
VerticalContentAlignment属性。

#5


引用 3 楼 duanzi_peng 的回复:
<PasswordBox Height="36" Name="passwordBox" Margin="5" Padding="0" VerticalContentAlignment="Center">

兄弟你好快啊,那就给你吧

#6


private void SetSelection(PasswordBox passwordBox, int start, int length)

    passwordBox.GetType()
               .GetMethod("Select", BindingFlags.Instance | BindingFlags.NonPublic)
               .Invoke(passwordBox, new object[] { start, length }); 

#7


引用 6 楼 u010278124 的回复:
private void SetSelection(PasswordBox passwordBox, int start, int length)

    passwordBox.GetType()
               .GetMethod("Select", BindingFlags.Instance | BindingFlags.NonPublic)
               .Invoke(passwordBox, new object[] { start, length }); 

解决了我的问题,哈哈,和lz的问题倒是无关
感谢!!!!!

#1


附上xaml
                    <PasswordBox Height="36" Name="passwordBox" Margin="5" Padding="0">
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="PasswordChanged">
                                <i:InvokeCommandAction Command="{Binding SetPasswordCommand}"
                                                       CommandParameter="{Binding ElementName=passwordBox, Path=Password}"/>
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </PasswordBox>

#2



            <PasswordBox Height="36" Name="passwordBox" Margin="5" Padding="0" VerticalContentAlignment="Center">

#3


<PasswordBox Height="36" Name="passwordBox" Margin="5" Padding="0" VerticalContentAlignment="Center">

#4


呵呵,柳暗花明又一村啊,看了半天没看到,发完贴突然就找到了。
VerticalContentAlignment属性。

#5


引用 3 楼 duanzi_peng 的回复:
<PasswordBox Height="36" Name="passwordBox" Margin="5" Padding="0" VerticalContentAlignment="Center">

兄弟你好快啊,那就给你吧

#6


private void SetSelection(PasswordBox passwordBox, int start, int length)

    passwordBox.GetType()
               .GetMethod("Select", BindingFlags.Instance | BindingFlags.NonPublic)
               .Invoke(passwordBox, new object[] { start, length }); 

#7


引用 6 楼 u010278124 的回复:
private void SetSelection(PasswordBox passwordBox, int start, int length)

    passwordBox.GetType()
               .GetMethod("Select", BindingFlags.Instance | BindingFlags.NonPublic)
               .Invoke(passwordBox, new object[] { start, length }); 

解决了我的问题,哈哈,和lz的问题倒是无关
感谢!!!!!