How to customize ToolTipProperties.Text for Image in .NET MAUI?

Sowndarrajan Vijayaragavan 330 Reputation points
2023-05-25T13:36:01.25+00:00

I added ToolTipProperties.Text for Image

By default it is showing in top.

But i need to show on left side.

Target platform - Windows

User's image

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,869 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 26,316 Reputation points Microsoft Vendor
    2023-05-29T09:06:39.7733333+00:00

    Hello,

    MAUI app can be written for Windows 11 and Windows 10 version 1809 or higher, using Windows UI Library (WinUI) 3.

    Since MAUI doesn't provide the API for accessing specific Windows platform ToolTipService placement , you can try to find the platform view with handler, then invoke the Windows-App-SDK code.

    public MainPage()
        {
            InitializeComponent();
            this.Loaded += MainPage_Loaded;
       }
      
        private void MainPage_Loaded(object sender, EventArgs e)
        {
    #if WINDOWS
    
           var image = MyImage.Handler.PlatformView as Microsoft.UI.Xaml.Controls.Image;// There is a MAUI Image named "MyImage“ in the Page
            Microsoft.UI.Xaml.Controls.ToolTip toolTip = new Microsoft.UI.Xaml.Controls.ToolTip();
            toolTip.Content = "Click to submit";
            toolTip.Placement = Microsoft.UI.Xaml.Controls.Primitives.PlacementMode.Right;// calling Windows platform method 
            ToolTipService.SetToolTip(image, toolTip);
    
    #endif
    }
    

    As noted at Doc- Display tooltips - .NET MAUI | Microsoft Learn: Configuring tooltip placement is currently unsupported. And there is a feature request at Github- [Enhancement] Add ToolTip and ToolTipPlacement properties #1889, you could follow the progress.

    Best Regards,

    Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments