I'm using WPF-NotifyIcon, and am following this tutorial, and it works when I put the XAML code in my MainWindow.xaml, however once I move onto the "Creating the NotifyIcon from a Resource Dictionary" part it stops showing up in the tray.
I have a Dictionary1.xaml with the following code in it:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:tb="http://www.hardcodet.net/taskbar">
<!-- Globally declared notify icon -->
<tb:TaskbarIcon x:Key="MyNotifyIcon"
IconSource="/Notifier;component/assets/icon_16x.ico"
ToolTipText="Notifier" MenuActivation="RightClick" Visibility="Visible" />
</ResourceDictionary>
An App.xaml with the following code:
<Application x:Class="Notifier.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary Source="Dictionary1.xaml" />
</Application.Resources>
</Application>
and I just copied over the App class code from that section of the tutorial.
What am I doing wrong? Why isn't the icon showing up? And on a related note, how can I have a program that doesn't have a MainWindow, but instead just runs from the taskbar (Which would be ideal with this control).
Edit:
I took out the StartupUri from App.xaml and put the following code in my App.xaml.cs:
protected override void OnStartup(StartupEventArgs e) {
base.OnStartup(e);
tb = (TaskbarIcon)FindResource("MyNotifyIcon");
tb.Visibility = Visibility.Visible;
//new MyClassIWantToInstantiate();
}
It works perfectly, but is there anything wrong with doing this?
You should be adding that
ResourceDictionary
to theMergedDictionaries
section if you want to use the resources normally.Example: