How does one change the titile bar image (the top-left most icon) 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.
</Grid> <Button x:Name="CloseButton" Background="Red" Style="{StaticResource CloseButtonStyle}" /> </StackPanel> </Grid>
"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."
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.
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
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"**>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With