How to create DynamicResource in code?

Hi all,

I have a program to play slideshow. All images are imported in run-time than use XmlWriter to save. Likes below.

....

<Grid.Resources>
<BitmapImage UriSource="20040714_lsps9140723_20213.jpg" x:Key="Bitmap1" />
<BitmapImage UriSource="20051010_ak0674661_030324.jpg" x:Key="Bitmap2" />

</Grid.Resources>
....

<DrawingCollection >
<ImageDrawing ImageSource ="{DynamicResource Bitmap1}"/>
<ImageDrawing ImageSource ="{DynamicResource Bitmap2}"/>
</DrawingCollection >

My question is, How to create ImageSource ="{DynamicResource Bitmap1}" in code

Thanks.



Answer this question

How to create DynamicResource in code?

  • gtjr92

    You dont need DynamicResource, StaticResource would do if I understand correctly

    in the code, you can say something like

    imageDrawing1.Imagesource = this.FindResource("Bitmap1") as BitmapImage;



  • BrainWasher

    I think markup extensions except those for data binding are useless when doing things in code.

    Sheva


  • How to create DynamicResource in code?