Binding RibbonWindow.Icon

Feb 2, 2011 at 12:29 PM
Edited Feb 2, 2011 at 12:33 PM

Binding an icon to the RibbonWindow.Icon seems to suppress the icon from appearing in the title bar (top-left).


  • Start with Fluent.Sample.Foundation.
  • Add to Window.xaml: <Fluent:RibbonWindow ... Icon="{Binding MyIcon}" ...
  • Add to Window.xaml.cs:
    •         public Window()
      DataContext = this;

      private System.Windows.Media.ImageSource _GetResourceImage(string resourceName)
      var url = @"pack://application:,,,/Fluent.Sample.Foundation;component/" + resourceName;
      var uri = new System.Uri(url);
      return new System.Windows.Media.Imaging.BitmapImage(uri);

      public System.Windows.Media.ImageSource MyIcon { get { return _GetResourceImage(@"Images/Fluent.ico"); } }
  • Run. Note that the icon does not appear anymore.

When using a normal Window instead of a RibbonWindow, this works as expected (the icon appears). And other Fluent icons (like Fluent:Button Icon) can be set with this approach without a problem.

Why does this not work with RibbonWindow? Is this a bug?

Thanks and keep up the great work!

Apr 12, 2011 at 7:45 AM

This is a bit strange since this works in a normal Window, and RibbonWindow inherits the Icon dependency property from there. Could the special NativeMethods.WM_SETICON handling in RibbonWindow cause this? Or the way the theme binds to that property?

The Office2010 theme seems to do this:

<Image x:Name="iconImage" Height="16" HorizontalAlignment="Left" VerticalAlignment="Top" Source="{Binding Icon, Converter={StaticResource IconConvert}, RelativeSource={RelativeSource TemplatedParent}}" Width="16" SnapsToDevicePixels="True"/>

What does the IconConverter do?
Apr 12, 2011 at 8:05 AM

As you know Icon is not a just bitmap image. As far as I remember you should use BitmapFrame class (see BitmapFrame.Create in msdn for further info).


Apr 13, 2011 at 7:16 AM

Thanks for the hint! In the above example I tried your suggestion and replaced the following line:

            return System.Windows.Media.Imaging.BitmapFrame.Create(uri);
            //return new System.Windows.Media.Imaging.BitmapImage(uri);

This change makes the icon appear. Yay! :)

The MSDN documentation seems not particularly instructive. By "Icon is not a just bitmap image" do you mean that icons have multiple resolutions? Any idea why the original code works with a non-ribbon Window but not with RibbonWindow?