Show window icon in title bar with MahApps.Metro?

MSmS picture MSmS · Jan 18, 2015 · Viewed 10.9k times · Source

I started using MahApps.Metro just yesterday, and I can't figure out how to get application icon to show as window icon on a window (or better, all of them). Here in the example window icon is included, but I can't seem to get it. When I use

ShowIconOnTitleBar="True"

it doesn't do anything. What am I doing wrong?

Answer

Mickael V. picture Mickael V. · Jan 18, 2015

You need to set the Iconproperty like this example (taken from the Mahapps demo app) :

<Controls:MetroWindow x:Class="MetroDemo.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
Title="MahApps.Metro - Demo Application"
        Width="960" Height="600"
        Icon="mahapps.metro.logo2.ico"
        ShowIconOnTitleBar="True"
        ShowTitleBar="True">
    <Grid />
</Controls:MetroWindow>

I suggest that you download the source code for the Mahapps project, which also contains the source for a demo app (too bad they don't advertise it on their website), it's great for examples. You can find it on GitHub here