以下のコード行を使用して、WPF でシステム トレイ アイコンを作成しようとしています。
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>
Google で解決策を検索しましたが、WPF を学習しようとしています。これは、システム トレイ アイコンを作成するときに発生した問題です。私が受け取るメッセージを以下に示します。
アセンブリ 'WpfExample、Version=1.0.0.0、Culture=neutral、PublicKeyToken=null' で定義された 'Window1' のインスタンスを作成できません。呼び出しのターゲットによって例外がスローされました。マークアップ ファイル 'Window1.xaml' の行 1 位置 9 にエラーがあります。
誰かが私を正しい方向に向けることができますか?