Reputation: 1683
My WPF form has a customized PasswordBox and this PasswordBox seem not receive mouse click event. When i click it no Caret appears. Here is my style for PasswordBox:
<Style x:Key="password" TargetType="{x:Type PasswordBox}">
<Setter Property="Controller:PasswordBoxMonitor.IsMonitoring" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type PasswordBox}">
<Border Name="Bd" Background="{TemplateBinding Background}"
BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}"
SnapsToDevicePixels="true">
<Grid>
<ScrollViewer x:Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
<my:QETextBlock Text="Mật khẩu" Margin="0, 0, 0, 0" Visibility="Collapsed" FontStyle="Normal" Name="txtPrompt" FontSize="12" FontFamily="Segoe UI" />
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
</Trigger>
<Trigger Property="Controller:PasswordBoxMonitor.PasswordLength" Value="0">
<Setter Property="Visibility" TargetName="txtPrompt" Value="Visible" />
</Trigger>
<Trigger Property="IsFocused" Value="True">
<Setter Property="Visibility" TargetName="txtPrompt" Value="Hidden" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
I try to get this control be focus by adding an event handler for mouse down event of this control:
txtPassword.MouseDown += txtPassword_MouseDown;
my txtPassword_MouseDown function:
private void txtPassword_MouseDown(object sender, MouseButtonEventArgs e)
{
txtPassword.Focus();
}
But this function doesn't be excuted when i click PasswordBox.
Upvotes: 1
Views: 1017
Reputation: 1683
I solved it. Someone set IsHitTestVisible="False"
that's why it didn't response to mouse clicks.
Upvotes: 1