How to set Icon of a Window in WPF

The following example shows how to set a window icon in XAML.

 

<Window

  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

  x:Class="SDKSample.MainWindow"

    Icon="WPFIcon1.ico">

</Window>

 

The following example shows how to set a window icon in C# and WPF.

 

// Set an icon using code

Uri iconUri = new Uri("pack://application:,,,/WPFIcon2.ico", UriKind.RelativeOrAbsolute);

this.Icon = BitmapFrame.Create(iconUri);