DanilaNV
DanilaNV

Reputation: 179

How to display tooltip in 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?

Upvotes: 3

Views: 14626

Answers (1)

Leigh S
Leigh S

Reputation: 1837

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>

Upvotes: 6

Related Questions