How to create DynamicResource in code?  
Author Message
GlynnChang





PostPosted: Windows Presentation Foundation (WPF), How to create DynamicResource in code? Top

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.



Visual Studio 200822  
 
 
lee d





PostPosted: Windows Presentation Foundation (WPF), How to create DynamicResource in code? Top

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;



 
 
Zhou Yong





PostPosted: Windows Presentation Foundation (WPF), How to create DynamicResource in code? Top

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

Sheva