Sturm
Sturm

Reputation: 4125

Merge images with .dll or .exe

I'm using 10-20 images in XAML and I don't want to distribute the app with all that files. I've read this question which refers to this article. It explains how to use Embedded Resources. The problem is that it seems to use that resources code behind using Reflection. In my case I have my images declared this way:

<Rectangle Width="30" Visibility="{Binding IsChecked, ElementName=maxCheck, Converter={StaticResource BoolVisConverter}}" Margin="-1 0 0 0">
 <Rectangle.Fill>
           <ImageBrush ImageSource="../Images/max.jpg" Stretch="Uniform"/>                  </Rectangle.Fill>
   </Rectangle>

I also have a SplashScreen that I want to merge among the others too. If possible I would like to include the icon as well.

I've searched a lot but still cannot find an easy solution to this problem. The ideal scenario would be to be able to merge ALL files needed for the execution of the program in a single .exe. That's because I expect this program to be movable, the users would easily forget copy some files when they will share the program.

Is there any guide, trick or whatever to achieve this? Thank you very much.

I'm using VS2012 and targeting .NET 4

Upvotes: 0

Views: 595

Answers (1)

user203570
user203570

Reputation:

Using Resource images is (relatively) easy in XAML and WPF. Read up on Pack URIs. Mark your images in the Solution Explorer as Resource (not Embedded Resource) and refer to them with a pack URI. For example:

<Rectangle Width="30"
           Visibility="{Binding IsChecked, ElementName=maxCheck, Converter={StaticResource BoolVisConverter}}"
           Margin="-1 0 0 0">
    <Rectangle.Fill>
        <ImageBrush ImageSource="pack://application:,,,/Images/max.jpg"
                    Stretch="Uniform"/>
    </Rectangle.Fill>
</Rectangle>

Upvotes: 1

Related Questions