Reputation: 10644
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
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