-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathElementToImageSourceConverter.cs
39 lines (33 loc) · 1.39 KB
/
ElementToImageSourceConverter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
namespace Hbo.Sheepish
{
using Standard;
using System;
using System.Windows;
using System.Windows.Data;
class ElementToImageSourceConverter : IValueConverter
{
private static void _RoundSizeToInt(ref Size iconSize)
{
iconSize.Width = Math.Round(iconSize.Width);
iconSize.Height = Math.Round(iconSize.Height);
}
#region IValueConverter Implementation
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var element = (FrameworkElement)value;
Size sourceSize = new Size(SystemParameters.IconWidth, SystemParameters.IconHeight);
if (parameter != null && parameter.ToString().Equals("Small", StringComparison.InvariantCultureIgnoreCase))
{
sourceSize = new Size(SystemParameters.SmallIconWidth, SystemParameters.SmallIconHeight);
}
Size iconSize = DpiHelper.LogicalSizeToDevice(sourceSize);
_RoundSizeToInt(ref iconSize);
return Utility.GenerateBitmapSource(element, (int)iconSize.Width, (int)iconSize.Height, true);
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
#endregion
}
}