locked
TypeConverter error when using pack URIs for images in a DLL RRS feed

  • Question

  • Background: I am a designer who is new to Blend and XAML and WPF.  

    Description: I have a DLL containing a number of icons for use in our GUI and I am laying out some controls using XAML in Blend 4.  Additionally, I have a sample application and my XAML needs to follow the same format at this sample (existing products).  The sample XAML was created by hand, but I would prefer to use Blend.  The problem I am having is getting icons to display in Blend when using pack URIs in the same format as the sample app.  Images in the sample use pack URIs with the following format:

    <RibbonButton Id="ID_Button1" Text="Button1" Image="pack://application:,,,/ApplicationResources;component/Resources/Images/Ribbon/icon1.ico" />
    

    I have created a WPF project and added a simple DLL containing four icons to the project.  When I use the format above, I get an error: The TypeConverter for "ImageSource" does not support converting from a string. 

    Now, if I specify the icon first in the Window.Resources, I can get the icon to display using the following:

     

    ...
    <Window.Resources>
    	<BitmapImage UriSource="pack://application:,,,/WpfCustomControlLibrary1;component/Images/icon1.ico" x:Key="testIco" />
    </Window.Resources>
    ...
    <RibbonButton Id="ID_Button1" Text="Button1" Image="{StaticResource testIco}" />
    ...
    

     

    I will end up having hundreds of icons, so would prefer a solution in which I do not have to specify each in the Window Resources, but rather specify them directly for the "Image=".  Also, like I said my XAML needs to follow the format of the existing apps.

    Thanks in advance for any help!

     

    Here is an example showing a working button image and a nonworking button image:

    <Window
    	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    	<!--Removed for product privacy-->
    	xmlns:sys="clr-namespace:System;assembly=mscorlib"
    	xmlns:system="clr-namespace:System;assembly=System"
    	x:Class="WpfApplication1.MainWindow"
    	x:Name="Window"
    	Title="MainWindow"
    	Width="1000" Height="160">
    	
    	<Window.Resources>
    		<BitmapImage UriSource="pack://application:,,,/WpfCustomControlLibrary1;component/Images/icon1.ico" x:Key="testIco" />
    	</Window.Resources>
    
    	<Grid x:Name="LayoutRoot">
    		<RibbonControl Margin="0" VerticalAlignment="Top" d:LayoutOverrides="Width">
    			<RibbonTab Id="ID_Tab1" Title="Tab1" IsActive="True" IsVisible="True">
    				<RibbonPanel>
    					<RibbonPanelSource Id="ID_Panel1" Title="Panel1">
    						<!--The image on Button1 shows up-->
    						<RibbonButton Id="ID_Button1" Text="Button1" Image="{StaticResource testIco}" ShowText="True" ShowImage="True"/>
    <!--Button2 results in an error, The TypeConverter for "ImageSource" does not support converting from a string. --> <RibbonButton Id="ID_Button2" Text="Button2" Image="pack://application:,,,/WpfCustomControlLibrary1;component/Images/icon1.ico" ShowText="True" ShowImage="True"/> </RibbonPanelSource> </RibbonPanel> </RibbonTab> </RibbonControl> </Grid> </Window>

     


    • Edited by RyanADSK Friday, July 8, 2011 2:16 PM formatting and typo
    Friday, July 8, 2011 2:14 PM

All replies

  • I don't have the pieces installed I would need to test this, but I wonder if this would work:

     

    <RibbonButton Id="ID_Button2" Text="Button2" ShowText="True" ShowImage="True">
    <RibbonButton.Image>
    <BitmapImage UriSource="pack://application:,,,/WpfCustomControlLibrary1;component/Images/icon1.ico" />
    </RibbonButton.Image>
    </RibbonButton>

    Friday, July 8, 2011 6:45 PM
    Moderator
  • Chuck, the image does show up when I do that.  I'm not sure if this gets me closer or not?

    (I'm leaving town for the weekend and will not be able to reply again until Monday morning)

    Friday, July 8, 2011 7:05 PM