向FlyoutMenu添加工具提示

时间:2017-02-18 12:27:30

标签: c# uwp

我的uwp应用中有一个FlyoutMenu。它工作正常,但我想在某些项目中添加工具提示。我能这样做吗?

如果您不是在使用uwp,则可能会对此处的相关问题感兴趣: Showing a tooltip for a MenuItem

class WindowsMenuFlyoutItem: Windows.UI.Xaml.Controls.MenuFlyoutItem
{
    public ICommonMenuItem InnerItem { get; set; }
    public WindowsMenuFlyoutItem (MyModelObject inner) {
        this.Text = inner.GetTitle().Text;
        this.Tapped += WindowsMenuFlyoutItem_Tapped;
        // set tooltip?
    }

    private void WindowsMenuFlyoutItem_Tapped(Object sender,
                                             Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
    {
        // handler here . . .
    }
}

1 个答案:

答案 0 :(得分:0)

试试这个:

private void WindowsMenuFlyoutItem_Tapped(object sender, TappedRoutedEventArgs e)
{
    MenuFlyoutItem item = sender as MenuFlyoutItem;
    ToolTipService.SetToolTip(item, "tooltip...");
}

或者如果您想在点击项目之前立即设置它:

public class WindowsMenuFlyoutItem : Windows.UI.Xaml.Controls.MenuFlyoutItem
{
    public ICommonMenuItem InnerItem { get; set; }
    public WindowsMenuFlyoutItem(MyModelObject inner)
    {
        this.Text = inner.GetTitle().Text;
        this.Tapped += WindowsMenuFlyoutItem_Tapped;

        Windows.UI.Xaml.Controls.ToolTipService.SetToolTip(this, "tooltip...");
    }
}