ググってもなかなか正解に辿りつけなかったのでメモ。
まず .ico ファイルをリソースに追加する
Resource フォルダ(なければ追加)にドラッグ・アンド・ドロップで追加します。
XAML で設定する方法
MainWindow.xaml
<Window x:Class="DiffFileSaver.Views.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
xmlns:l="http://schemas.livet-mvvm.net/2011/wpf"
xmlns:v="clr-namespace:DiffFileSaver.Views"
xmlns:vm="clr-namespace:DiffFileSaver.ViewModels"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:scg="clr-namespace:System.Collections.Generic;assembly=mscorlib"
Title="DiffFileSaver"
Height="318.182"
Width="525"
Icon="/DiffFileSaver;component/Resources/unWatching.ico">
<!-- 省略 -->
</Window>
パスの書き方は、
/<プロジェクト名>;component<リソースファイルのパス>
です。
コード側から設定する方法
MainWindow.xaml.cs
this.Icon = BitmapFrame.Create(new Uri("pack://application:,,,/Resources/unWatching.ico", UriKind.RelativeOrAbsolute));
パスの書き方は XAML と異なり、
pack://application:,,,<リソースファイルのパス>
です。
こちらを用いれば動的に変更できます。