Search code examples
c#silverlightxamltabitem

Image is not visible in Tabitem Header in Silverlight application


I am designing a TabItem by adding StackPanel which contains an Image and Textblock, and the XAML code is as follows,

XAML:

<sdk:TabItem    
      Name="adminTab" 
      BorderBrush="Black" 
      Background="#F5C162" 
      RenderTransformOrigin="0.5,0.5" 
      Margin="0,0,0,-14" 
      BorderThickness="1,1,1,0">
    <sdk:TabItem.Header>
        <StackPanel Background="#F5C162" 
                    Width="80" Height="30" 
                    Orientation="Horizontal" 
                    Margin="-7,-3,-11,-23" 
                    HorizontalAlignment="Left" 
                    VerticalAlignment="Top">
            <Image Name="ico1" 
                   Height="20" Width="20" 
                   Source="TabIcons/Admin.ico" 
                   Stretch="Fill" HorizontalAlignment="Left" 
                   VerticalAlignment="Top" Margin="5,5,0,0"/> 
            <TextBlock Text="Admin" Margin="5,5,0,0" 
                           HorizontalAlignment="Left" 
                           VerticalAlignment="Top" />
        </StackPanel>
    </sdk:TabItem.Header>
</sdk:TabItem>

I am supposed to display image but actually it appears as below,

enter image description here

Can anyone help me with this?


Solution

  • I don't believe .ico image formats are supported by Silverlight.

    From the Image.Source MSDN:

    Silverlight does not support all image formats. See BitmapImage for information on the types of image sources and formats that can be used for an Image.

    On that BitmapImage page:

    The BitmapImage can be used to reference images in the JPEG and PNG file formats.

    This is different than the Image control used in WPF/Windows8 which does appear to support .ico files.

    Unfortunately, I think you'll have to try converting your ICO file to a PNG or JPG.