Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display tooltip in XAML?

Tags:

wpf

tooltip

xaml

I'm writing an application using WPF MVVM. I have a view model with property IsFolderSelected like this:

public class SelectFolderViewModel : ViewModelBase
{        
    public bool IsFolderSelected
    {
        get
        {
            return _isFolderSelected;
        }

        set
        {
            if (_isFolderSelected == value)
            {
                return;
            }

            _isFolderSelected = value;
            RaisePropertyChanged(IsFolderSelectedPropertyName);
        }
    }
 }

And i have a TextBox element in XAML:

        <TextBox 
             Text="{Binding Path=FolderPath}"
             ToolTip="Please select folder"/>

How can i force display tooltip from the TextBox when property IsFolderSlected == false?

like image 295
DanilaNV Avatar asked Dec 05 '25 12:12

DanilaNV


1 Answers

To keep with your MVVM model I think it will be difficult to achieve with a tooltip. You could use a popup and bind the IsOpen property.

<TextBox Grid.Row="1" x:Name="folder"
     Text="{Binding Path=FolderPath}"
     ToolTip=""/>
</TextBox>

<Popup PlacementTarget="{Binding ElementName=folder}" IsOpen="{Binding IsFolderSelected, Mode=TwoWay}">
    <Border Margin="1">
        <TextBlock Background="White" Foreground="Black" Text="Please select folder"></TextBlock>
    </Border>
</Popup>
like image 185
Leigh S Avatar answered Dec 08 '25 07:12

Leigh S



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!