Given the xaml for a image button, I have code to load an image, but this consistantly fails at the call to loadedImage.SetSource(e.Result);// <== Fails here with Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))public void LoadImage(string ImageURL)
{
//
// Creating WebClient object and setting up events
//
WebClient downloader = new WebClient();
downloader.OpenReadCompleted +=
new OpenReadCompletedEventHandler(downloader_OpenReadCompleted);
//
// Specify Image to load
//
downloader.OpenReadAsync(
new Uri(ImageURL, UriKind.RelativeOrAbsolute));
}
void downloader_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
//
// Create a new BitmapImage and load the stream
//
try
{
BitmapImage loadedImage = new BitmapImage();
//Image loadedImage = new Image();
loadedImage.SetSource(e.Result);// <== Fails here with Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))
// Setting our BitmapImage as the source of a BackgroundImage control I have in XAML
this.btnImg.Source = loadedImage;
}
catch (Exception)
{
//ToolTipService.SetToolTip(this.btnButton, new ToolTip { Content = e.Error });
}
}
<
UserControl
xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns
:x="http://schemas.microsoft.com/winfx/2006/xaml"
x
:Class="ImageButtonWLink.MainControl"
mc:Ignorable="d"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Height="40" Width="200">
<Canvas x:Name="cnvLayoutRoot" Background="{x:Null}" >
<Button x:Name="btnButton" Background="White" Width="199.991" Canvas.Top="-0.009" Canvas.Left="-0.009" Click="btnClickEvent" Height="40" >
<StackPanel x:Name="spnlButtonContent" VerticalAlignment="Center" Orientation="Horizontal" Width="195.138">
<Image x:Name="btnImg" Width="30" Height="30" Source="/ImageButtonWLink;component/Images/Comments-info.png" Stretch="None" />
<TextBlock x:Name="btnText" Text="Set text via btnText " FontWeight="Bold" Foreground="#1ca0f2" VerticalAlignment="Center" Width="159.84" HorizontalAlignment="Stretch" Padding="4" />
</StackPanel>
</Button>
</Canvas>
</
UserControl>