How does one change the titile bar image (the top-left most icon) in WPF?
Asked
Active
Viewed 7.8k times
6 Answers
55
The Icon attribute of Window is used to set Icon of a window.
<Window x:Class="WindowSample.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WPF Window Sample" Height="350" Width="525"
Name="FirstWindow" Icon="Icon1.ico" >
The Icon property of Window class represents a window's icon at run-time. This property takes an ImageSource variable.
The following code snippet uses BitmapFrame.Create method to create an ImageSource and sets the Icon property of a Window.
Uri iconUri = new Uri("pack://application:,,,/Icon1.ico", UriKind.RelativeOrAbsolute);
this.Icon = BitmapFrame.Create(iconUri);
You can read more from here

kamaci
- 72,915
- 69
- 228
- 366
19
Easy way to add image to title bar:
In your Project, Select - Properties - Application - Resources - Icon and Manifest - select the .ico image(always convert your image to .ico)
Add this line(icon) in WPF Main window:
Title="xxxxx" **Icon="xxxxxx.ico"**>

EM-Creations
- 4,195
- 4
- 40
- 56

Praveen Gopal
- 529
- 8
- 23
-
R click on project in the solution explorer menu > properties > application > resources – Mike Oct 16 '17 at 17:40
9
<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>
or in code
// Set an icon using code
Uri iconUri = new Uri("pack://application:,,,/WPFIcon2.ico", UriKind.RelativeOrAbsolute);
this.Icon = BitmapFrame.Create(iconUri);
Source: Window.Icon Property

Jens
- 3,249
- 2
- 25
- 42
4
This one worked for me (using Visual Studio 2017)
- Select menu Project/[yourprojectname] Properties
- Click Application tab (its the first one on top)
- Here you can browse for Icon, and it will be copied to your project

mgear
- 1,333
- 2
- 22
- 39
2
- Add ico file to project Resources and check as Embedded Resource
- Set Project->Properties->Icon and choose from Resources
- Run Project in Release Mode or start without debugging.

Krzysztof Gapski
- 528
- 6
- 10
-
While these few steps was working for me, I am still puzzled why the default icon is showing in debug. – Tiny Sep 07 '15 at 13:15
-
1These steps don't make any sense in the context of visual studio. How do you add an icon to project "Resources"? Where is this "Properties->Icon" menu that you refer to? Etc. – Jake Oct 04 '16 at 20:11
-
R click on project in the solution explorer menu > properties > application > resources – Mike Oct 16 '17 at 17:40