Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does one change title bar image in WPF Window?

Tags:

wpf

How does one change the titile bar image (the top-left most icon) in WPF?

like image 423
KMC Avatar asked Feb 24 '11 08:02

KMC


People also ask

How do I change the title bar in WPF?

In WPF the titlebar is part of the non-client area, which can't be modified through the WPF window class. You need to manipulate the Win32 handles (if I remember correctly). – Lyle S. @LyleS.

How do I change the color of the title bar in WPF?

</Grid> <Button x:Name="CloseButton" Background="Red" Style="{StaticResource CloseButtonStyle}" /> </StackPanel> </Grid>

How do I change the icon in WPF?

"First go to Resource View (from menu: View --> Other Window --> Resource View). Then in Resource View navigate through resources, if any. If there is already a resource of Icon type, added by Visual Studio, then open and edit it. Otherwise right-click and select Add Resource, and then add a new icon."

Can you resize with grip?

The CanResizeWithGrip option is similar to CanResize, but the lower right corner of the window shows a little “grip” icon indicating that you can “grab” the window here to resize it. The NoResize option creates a window that can't be resized, minimized or maximized.


2 Answers

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

like image 146
kamaci Avatar answered Sep 19 '22 21:09

kamaci


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"**> 
like image 23
Praveen Gopal Avatar answered Sep 22 '22 21:09

Praveen Gopal