SIGN UP MEMBER LOGIN:    
ARTICLE

Windows Icon in WPF

Posted by Mahesh Chand Articles | WPF with C# 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'>
Login to add your contents and source code to this article
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
Nevron Gauge for SharePoint
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    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!
Become a Sponsor