How does one change title bar image in WPF Window?
How does one change the titile bar image (the top-left most icon) in WPF?
Solution 1:
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
Solution 2:
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"**>
Solution 3:
<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