diff --git a/Stylet/Xaml/IconToBitmapSourceConverter.cs b/Stylet/Xaml/IconToBitmapSourceConverter.cs
index 1eab1b5..38c3a0f 100644
--- a/Stylet/Xaml/IconToBitmapSourceConverter.cs
+++ b/Stylet/Xaml/IconToBitmapSourceConverter.cs
@@ -5,6 +5,7 @@ using System.Windows;
using System.Windows.Data;
using System.Windows.Interop;
using System.Windows.Media.Imaging;
+using Stylet.Logging;
namespace Stylet.Xaml
{
@@ -14,6 +15,8 @@ namespace Stylet.Xaml
[SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1126:PrefixCallsCorrectly", Justification = "Don't agree with prefixing static method calls with the class name")]
public class IconToBitmapSourceConverter : IValueConverter
{
+ private static readonly ILogger logger = LogManager.GetLogger(typeof(IconToBitmapSourceConverter));
+
///
/// Singleton instance of this converter. Usage e.g. Converter="{x:Static s:IconToBitmapSourceConverter.Instance}"
///
@@ -32,13 +35,22 @@ namespace Stylet.Xaml
var icon = value as Icon;
if (icon == null)
return null;
- var bs = Imaging.CreateBitmapSourceFromHIcon(icon.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
- bs.Freeze();
- return bs;
+
+ try
+ {
+ var bs = Imaging.CreateBitmapSourceFromHIcon(icon.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
+ bs.Freeze();
+ return bs;
+ }
+ catch (Exception e)
+ {
+ logger.Error(e, String.Format("Error trying to call CreateBitmapSourceFromHIcon: {0}", e.Message));
+ return null;
+ }
}
///
- /// Converts a value back. Not implemented.
+ /// Converts a value back. Not supported.
///
/// value, as produced by target
/// target type
@@ -47,7 +59,7 @@ namespace Stylet.Xaml
/// Converted back value
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
- throw new NotImplementedException();
+ throw new NotSupportedException();
}
}
}
diff --git a/StyletUnitTests/IconToBitmapSourceConverterTests.cs b/StyletUnitTests/IconToBitmapSourceConverterTests.cs
index 0fc40b9..a0a5ea0 100644
--- a/StyletUnitTests/IconToBitmapSourceConverterTests.cs
+++ b/StyletUnitTests/IconToBitmapSourceConverterTests.cs
@@ -39,7 +39,7 @@ namespace StyletUnitTests
[Test]
public void ConvertBackThrows()
{
- Assert.Throws(() => this.converter.ConvertBack(null, null, null, null));
+ Assert.Throws(() => this.converter.ConvertBack(null, null, null, null));
}
}
}