Question

My application does a lot of work with currencies and so frequently makes use of 80-90 .ICO files I have as resources which are country flags, to represent each currency. Most screens use these and it seems a waste to keep reloading them for each use, especially given that when I use a datatemplate that has an IMG tag, it freezes the GUI or makes it very unperformant when loading these in ListViews etc.

Is there some way or design that's recommended in WPF whereby I can preload these images into the WPF application space so that whenever they are referenced, they are already cached and loaded globally so I only have to load them into memory once at application start, then every usage from then on in is lightning fast?

Thanks

Was it helpful?

Solution

I would suggest to place them into the Application.Resources in your xaml.

Those are loaded only once and accessible everywhere in your app.'

See How to: Use Application Resources on msdn.

EDIT: In your class where you bind your items too (class that contains IconSelect) you need to add an extra property.

public BitmapImage BitmapIconSelect
{
    get
    {
        return Application.Resources[IconSelect];
    }
}

And then bind to this property:

<Image Source="{Binding BitmapIconSelect, IsAsync=True, Mode=OneWay}" Width="20" Height="20" />

I wrote this code freehand, so I am not sure if it compiles but I hope you get my point.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top