3

I have a WPF project that has a link to another assembly that has only some resources in it (namely images and styles). The name of this assembly is Library.WPF.Resources

I can not access images in the resource assembly.

In resource assembly I included one image called but_close.png and set is property to

build action= content
copy to output directory = don't copy

In wpf application, I am using this image as follow

<Button  Canvas.Left="997" Canvas.Top="10" Width="16" Height="14" Style="{StaticResource TransparentButton}" x:Name="CloseWindow">
            <Image  >
                <Image.Style>
                    <Style TargetType="{x:Type Image}">
                        <Setter Property="Source" Value="pack://application:,,,/Library.WPF.Resources;component/Resources/Images/but_close.png"/>
                        <Style.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Source"  Value="/Library.WPF.Resources;component/Resources/Images/but_close_roll.png"/>
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </Image.Style>
            </Image>
        </Button

I can not see any problem when I look at the page contain this button on wpf application (no error indicating that application can not find it. but when I run the application, I am getting this error:

{"Cannot locate resource 'resources/images/but_close.png'."}

I opened the Library.WPF.Resources.dll in a hex editor and looked for but_close.png and I could not find it in dll.

Why the image is not included in dll?

I changed the build action of but_close.png in resource project to resource. Same issue, it is not included in dll.

Changed the build action of this image to embeddedresource. Now it is in dll, but still when I run the application I am getting error that resource can not be found.

My questions:

1- What is the correct build action for images in in a resource assembly?

2- Why can I access the image in another xaml page?

5
  • 2
    Build Action must be set to Resource. Then rebuild everything.
    – Clemens
    Apr 2, 2014 at 10:41
  • @Clemens: When I set the build action to Resource, I can not see my image in dll. I opened in dll in a hex editor and looked for but_close.png, and could not find it.
    – mans
    Apr 2, 2014 at 10:45
  • @mans That's ok. Also, you have folder Resources in project Library.WPF.Resources? Apr 2, 2014 at 10:47
  • @Clemens: yes I have, but I am using pack uri to point to Resources in my library assembly.
    – mans
    Apr 2, 2014 at 10:50
  • @Clemens: I moved the image directory in resource project to root, so the pack uri is : "pack://application:,,,/Library.WPF.Resources;component/Images/but_close.png" and I am getting that images/but_close.png can not be found.
    – mans
    Apr 2, 2014 at 10:56

1 Answer 1

0

Set the build action to "resource". Make sure the resources access modifier is "public"

Access the resource like this:

<Grid>
    <Image Source ="pack://application:,,,/Library.WPF;component/Resources/but_close.png" Stretch="Fill"/>
</Grid>
4
  • How can I set the resource access modifier to public?
    – mans
    Apr 2, 2014 at 12:18
  • Right click the project. Click "properties". In the Resources tab you will find several combox like "Add Resource" and also the "Access Modifier"
    – Ketobomb
    Apr 2, 2014 at 12:32
  • Did you try this solution?
    – Ketobomb
    Apr 7, 2014 at 8:30
  • Yes I did test it but it did not work. The resources in properties page are windoform properties and not wpf.
    – mans
    Apr 7, 2014 at 11:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.