Here is my code.
private void txtPassword_PasswordChanged(object sender, RoutedEventArgs e)
{
Boolean Capslock = Console.CapsLock;
if (Capslock == true)
{
txtPassword.ToolTip = "Caps Lock is On.";
}
}
I'm trying to get a tooltip to show on TextChanged Event on WPF Control. The above code works fine and shows the tooltip with the above text when I move my mouse over the txtPassword control if Caps Lock is on.
But I'm looking for something that will show the tooltip when you start typing regardless of mouse over txtPassword Control or not. Like when the txtPassword Control is focused or something similar
Any help will be appreciated.
You might want to consider using a PopUp for this.
XAML:
<TextBox x:Name="txtPassword" Height="30" Width="100" TextChanged="txtPassword_TextChanged" ></TextBox>
<Popup x:Name="txtPasswordPopup" Placement="Top" PlacementTarget="{Binding ElementName=txtPassword}" IsOpen="False">
<TextBlock x:Name="PopupTextBlock" Background="Wheat">CAPSLOCK IS ON!</TextBlock>
</Popup>
Code-Behind:
private void txtPassword_TextChanged(object sender, TextChangedEventArgs e)
{
Boolean Capslock = Console.CapsLock;
if (Capslock == true)
{
PopupTextBlock.Text = "Caps Lock is On.";
txtPasswordPopup.IsOpen = true;
}
else
{
txtPasswordPopup.IsOpen = false;
}
}