title: How can I make a notification in a C# Windows app with a custom image and onclick function?
body: <p>My ultimate goal is to have a Windows 10 app in C#.NET that displays a notification to the user. The notification should have a title, description, at least one image, and when clicked, it should open a webpage. It should also be stored in notification manager (or whatever that place in Windows that lists notifications is called) if the user doesn't click on it. So that's the goal.</p>
  <p>I've tried a bunch of different ways of doing this, and cannot get any of them to work properly.</p>
  <p>My current code uses the <code>Microsoft.Toolkit.Uwp.Notifications</code> NuGet package and is primarily taken from this sample:
  <a href="https://docs.microsoft.com/en-us/windows/uwp/design/shell/tiles-and-notifications/adaptive-interactive-toasts?tabs=builder-syntax" rel="noreferrer">https://docs.microsoft.com/en-us/windows/uwp/design/shell/tiles-and-notifications/adaptive-interactive-toasts?tabs=builder-syntax</a></p>
  <p>The following code works great, as far as it goes:</p>
  <pre><code>using System;
  using System.Windows;
  using Microsoft.Toolkit.Uwp.Notifications;
  
  namespace PushClient
  {
      public partial class App : System.Windows.Application
      {
          private void Application_Startup(object sender, StartupEventArgs e)
          {
              new ToastContentBuilder()
              .AddText(&quot;My Title&quot;)
              .AddText(&quot;My Description&quot;)
              .Show();
          }
      }
  }
  </code></pre>
  <p>Here is the notification it produces...</p>
  <p><a href="https://i.stack.imgur.com/Gw0OR.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/Gw0OR.jpg" alt="Just title and description" /></a></p>
  <hr />
  <p><strong>FIRST PROBLEM</strong></p>
  <p>The first problem is that I cannot add a custom image, even though there are supposedly three different methods through which an image can be added. I first tried this:</p>
  <pre><code>new ToastContentBuilder()
  .AddText(&quot;My Title&quot;)
  .AddText(&quot;My Description&quot;)
  .AddAppLogoOverride((new Uri(&quot;https://picsum.photos/48?image=883&quot;)), ToastGenericAppLogoCrop.Circle)
  .Show();
  </code></pre>
  <p>That successfully removes the default icon at the left of the notification and adds the name of the app at the bottom (since the idea is that the logo has been gotten rid of, so the app has to be identified through some other method). However, there is no new image in place of the old. Just blank space.</p>
  <p><a href="https://i.stack.imgur.com/DknXG.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/DknXG.jpg" alt="An empty icon area" /></a></p>
  <p>I also attempted this:</p>
  <pre><code>new ToastContentBuilder()
  .AddText(&quot;My Title&quot;)
  .AddText(&quot;My Description&quot;)
  .AddHeroImage(new Uri(&quot;https://picsum.photos/364/180?image=1043&quot;))
  .Show();
  </code></pre>
  <p>But that changed literally nothing from the first version as far as I could tell.</p>
  <p><a href="https://i.stack.imgur.com/75Enw.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/75Enw.jpg" alt="Same as the plain text version" /></a></p>
  <p>Finally I tried this:</p>
  <pre><code>new ToastContentBuilder()
  .AddText(&quot;My Title&quot;)
  .AddText(&quot;My Description&quot;)
  .AddInlineImage(new Uri(&quot;https://picsum.photos/360/202?image=1043&quot;))
  .Show();
  </code></pre>
  <p>That seems to have added some blank space beneath the description, but no image.</p>
  <p><a href="https://i.stack.imgur.com/hUSDg.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/hUSDg.jpg" alt="Blank space at foot" /></a></p>
  <hr />
  <p><strong>SECOND PROBLEM</strong></p>
  <p>Another problem is that I cannot figure out how to add a full onclick action through this process. I would be perfectly happy with either a button that needs to be clicked, or a click action on the notification itself. But however it works, it ultimately needs to open a specified URL in the user's default browser.</p>
  <hr />
  <p><strong>OTHER ATTEMPTS</strong></p>
  <p>I have also played with other processes of sending notifications, like the <code>ShowBalloonTip</code> process. This seems to have no option at all for a custom image, which is what I want. However, I can select an image from a specified list of images, including a &quot;warning&quot; icon, which I've chosen in this code, and the onclick action is simple to add:</p>
  <pre><code>using System;
  using System.Threading;
  using System.Windows;
  using System.Windows.Forms;
  
  namespace PushClient
  {
      public partial class App : System.Windows.Application
      {
          private NotifyIcon _notifyIcon = new NotifyIcon();
  
          private void Application_Startup(object sender, StartupEventArgs e)
          {
              try
              {
                  _notifyIcon = new NotifyIcon();
                  _notifyIcon.Icon = PushClient.Properties.Resources.accountable2you;
                  _notifyIcon.Visible = true;
                  _notifyIcon.ContextMenuStrip = new System.Windows.Forms.ContextMenuStrip();
  
                  Thread t = new Thread(() =&gt; LaunchBalloonNotification(_notifyIcon, &quot;My Title&quot;, &quot;My Description&quot;));
                  t.Start();
              }
              catch (System.Exception ex)
              {
                  Console.WriteLine(ex.ToString());
              }
          }
          private static void notifyIcon_BalloonTipClicked(object sender, EventArgs e)
          {
              Console.WriteLine(&quot;Action clicked&quot;);
          }
          private static void LaunchBalloonNotification(NotifyIcon ico, String title, String msg)
          {
              ico.ShowBalloonTip(
                  10000,
                  title,
                  msg,
                  ToolTipIcon.Warning
              );
              ico.BalloonTipClicked += new EventHandler(notifyIcon_BalloonTipClicked);
          }
      }
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/wqIuq.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/wqIuq.jpg" alt="No custom image" /></a></p>
  <p>I have also tried working with <code>ToastNotificationManager</code>, but the results I get with that are identical to the results I get with <code>Microsoft.Toolkit.Uwp.Notifications</code>... except that <code>ToastNotificationManager</code> requires an <code>AppID</code> to work, and I've had difficulty figuring out how I'm properly supposed to create such a thing for my little Visual Studio test app.</p>
  <p>Anyway, if you can point me in the right direction to help me achieve my goal here (preferably with a <a href="https://stackoverflow.com/help/minimal-reproducible-example">minimal, reproducible example</a>!), it would be much appreciated!</p>