开发者

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
{        
 开发者_StackOverflow   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?


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜