SIGN UP MEMBER LOGIN:    
ARTICLE

Windows Icon in WPF

Posted by Mahesh Chand Articles | WPF January 13, 2010
An Icon is a bitmap image (.ico file) that is displayed in the top left corner of a Window. This article discusses how to create and use Icons in WPF applications.
Reader Level:

An Icon is a bitmap image (.ico file) that is displayed in the top left corner of a Window. Visual Studio designer allows you to create your own icon images. To add an icon to a project, right click on

the project name in Solution Explorer. Right click will open Add Items menu.  Select Add >> New Item.

Now on Installed Templates, select Icon File (see Figure 1) and click Add. This action adds Icon1.ico file and opens the image editor.

WPFIconImg1.gif

Figure 1

In the image editor (see Figure 2), you design your icon the way you like. There are two icon sizes available in the editor - 16x16 and 32x32.

 WPFIconImg2.gif

Figure 2

The Icon attribute of Window is used to set Icon of a window. Listing 1 sets Icon1.ico file as icon of 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" >

Listing 1

The output with new icon looks like Figure 3.

WPFIconImg3.gif

Figure 3

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);


Summary


In this article, I demonstrated how to use Icon property of a Window to load an icon in a WPF application.


erver'>
share this article :
post comment
 

Yes but how we can say to WPF what of the 2 icon Use? Many Thanks

Posted by Achille Mar 01, 2010
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor