Willy
Willy

Reputation: 10644

Setting WPF Image's source from a Window icon (.ico)

I have set my WPF Window icon as below:

<Window Icon="icon3.ico">
  <Grid>
    <Image x:Name="img"></Image>
  </Grid>
</Window>

Now I am tring to set programmatically an WPF image's source with WPF Window icon:

this.img.Source = this.Icon as BitmapImage;

but this.img.Source is null after setting it. Why?

Upvotes: 1

Views: 1316

Answers (1)

Michael Puckett II
Michael Puckett II

Reputation: 6749

why not just

img.Source = Icon;

Maybe Icon isn't a BitmapImage type... either way, Icon is an ImageSource and the Source property on img is an ImageSource. You can just assign it directly always.

Upvotes: 2

Related Questions