Reputation: 10033
I am trying to create a system tray icon in WPF using the lines of code below:
System.Windows.Forms.NotifyIcon ni = new System.Windows.Forms.NotifyIcon();
ni.Icon = new System.Drawing.Icon("main.ico");
XAML:
> <Window x:Class="WpfExample.Window1"
> xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
> xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
> Title="Window1" Height="300" Width="300">
> <Grid>
> <Button Height="23" Margin="103,0,100,100" Name="button1"
> VerticalAlignment="Bottom">Submit</Button>
> <TextBox Height="23" Margin="77,75,81,0" Name="textBox1"
> VerticalAlignment="Top" />
> </Grid> </Window>
I've searched for a solution on Google but I'm trying to learn WPF and this is a problem I have hit when creating a system tray icon. The message I get is shown below:
Cannot create instance of 'Window1' defined in assembly 'WpfExample, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Exception has been thrown by the target of an invocation. Error in markup file 'Window1.xaml' Line 1 Position 9.
Can anyone point me in the right direction?
Upvotes: 1
Views: 2975
Reputation: 17647
I created a small sample application that displays a tray icon. You can try to run it and study how the code works. I uploaded it to the SkyDrive:
http://cid-1fe4c9928da08eaa.office.live.com/self.aspx/P%c3%bablico/Tray-WpfApplication1.zip
Upvotes: 1
Reputation: 17647
The .ico must be on a standard format, size, colors. I had a issue with this.
Try to get and use this icon file and tell if it work:
http://www.iconarchive.com/download/visualpharm/must-have/Check.ico
There are more icons here:
http://www.iconarchive.com/category/system/must-have-icons-by-visualpharm.html
Upvotes: 1