如何将鼠标悬停在按钮上进行工具提示

时间:2014-04-23 06:27:43

标签: c# .net silverlight mouseevent toolkit

我是c#silverlight(5)初学者,并且不知道如何制作工具提示。事实上,我无法在工具箱中找到任何工具提示选项。

我需要做的是在鼠标悬停按钮时显示工具提示。假设我有这样的按钮:

<Button Content="{Binding Path=Id}"
        Command="{Binding DataContext.ShowPopupCommand,
                   RelativeSource={RelativeSource AncestorType=data:DataGrid}}"/>

现在如何在ViewModel.cs类中的此按钮上创建工具提示?

有人可以请教我如何使用MVVM方法在c#silverlight应用程序中创建ToolTip。任何帮助的代码都非常感谢。会是一个很大的帮助。感谢。

2 个答案:

答案 0 :(得分:2)

<Button
    ToolTipService.ToolTip="ToolTip based on the mouse."
    ToolTipService.Placement="Mouse"/>

如果您需要显示任何FrameworkElements(而不仅仅是文字),可以像这样设置工具提示:

<Button>
    <ToolTipService.ToolTip>
        <Border Background="Pink">
            <StackPanel>
                <Image .../>
                <TextBlock .../>
            </StackPanel>
        </Border>
    </ToolTipService.ToolTip>
</Button>

答案 1 :(得分:1)

试试这个

<Button Content="{Binding Path=Id}"
        Command="{Binding DataContext.ShowPopupCommand,
            RelativeSource={RelativeSource AncestorType=data:DataGrid}}"
        ToolTip="{Binding SomeProperty}"/>