Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wpf - Show Textbox ToolTip

Tags:

c#

.net

wpf

<TextBox Name="txtInput">
<TextBox.ToolTip>
    <ToolTip Name="TestToolTip">
        This a test message
    </ToolTip>
</TextBox.ToolTip>

private void btnClick_Click_1(object sender, RoutedEventArgs e)
{
    txtInput.Focus();
    ToolTipTest.IsVisible = true;
}

When the button is clicked the tooltip is shown on the button, I want to simulate putting mouse pointer on the textbox, the toolbox to be shown for the textbox

like image 831
Svetlozar Angelov Avatar asked Oct 22 '25 14:10

Svetlozar Angelov


1 Answers

First of all, you should be using the standard validation for something like what you are doing. From your comment above I can tell that's what you are doing and you should know that WPF has a really good builtin system for doing exactly what you want without doing it so imperatively (and very reusable).

Here's an example of a style you can apply to, say, all textboxes when the value the are bound to doesn't validate (using IDataErrorInfo).

<Style.Triggers>
    <Trigger Property="Validation.HasError" Value="true">
        <Setter Property="ToolTip">
           <Setter.Value>
                <ToolTip Content="{Binding RelativeSource={RelativeSource Self}, 
                   Path=(Validation.Errors)[0].ErrorContent}" IsOpen="true" />
           </Setter.Value>
        </Setter>
    </Trigger>
</Style.Triggers>

You might also consider a more standard UI that utilizes the adorner layer to put a validation failure indicator next to the control that failed validation. Here's a sample on that:

http://blogsprajeesh.blogspot.com/2009/03/handling-error-in-wpf-idataerrorinfo.html

Good luck.

like image 135
Anderson Imes Avatar answered Oct 24 '25 03:10

Anderson Imes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!