Icons of an F# WPF application
There are at least two different usages for icons. First, there is the application icon displayd on the top left corner of the application window and also in the task bar. Second, Windows Explorer shows application icons in the file lists and also uses them for shortcuts.
- Create the icon. For example, save an image with Paint as a 256 color bitmap and change the file extension to *.ico
- Save the icon in an “Resources” subfolder of the project
- Set the Build Action of the icon to Resource
- Include the icon with the XAML file
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Icon="/Resources/MyIcon.ico" Title="MyApplication" Height="600" Width="1000" >
Windows Explorer icon
- Save the icon in 3.00 format using the free tool @icon sushi.
- Create a text file with a *.rc extension. Save the *.rc file in the “Resources” subfolder.
- The *.rc file should contain a single line. The ‘1’ is part of the text and not a line number.
1 ICON "MyIcon.ico"
- Ensure that the Resource Compiler rc.exe is installed. Adding the C++ Tools to Visual Studio should also install rc.exe.
- Compile the *.rc file with rc.exe into an *.res file.
C:\Program Files (x86)\Windows Kits\10\bin\x86>rc.exe /v C:\pathToMyFile\Resources\MyResources.rc
- In Visual Studio, select the Application tab of project property page
- Select the compiled *.res file in the Resources section. The complete absolute path to the file is shown. Leave the tick box “Use standard resource names” unchecked.
- With a text editor edit the project *.fsproj file. Change the absolut path to a relative path.
Visual Studio should be closed.