blob: 1d48c48861aac0958983e2a0d87e952d27a10771 (
plain)
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
40
41
42
43
44
45
46
|
using System;
using System.Globalization;
using System.Linq;
using System.Windows.Data;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Xamarin.PropertyEditing.Drawing;
namespace Xamarin.PropertyEditing.Windows
{
[ValueConversion (typeof (CommonBrush), typeof (Brush))]
internal class CommonBrushToBrushConverter : MarkupExtension, IValueConverter
{
public object Convert (object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null) return null;
if (value is CommonSolidBrush solidBrush) return new SolidColorBrush (solidBrush.Color.ToColor ());
// TODO: revisit this with more details when we build the editors for those brushes
if (value is CommonImageBrush imageBrush) {
return new ImageBrush (new BitmapImage (new Uri (imageBrush.ImageSource)));
}
if (value is CommonLinearGradientBrush linearGradientBrush) {
return new LinearGradientBrush (
new GradientStopCollection (linearGradientBrush.GradientStops.Select (stop => new GradientStop (stop.Color.ToColor (), stop.Offset))),
linearGradientBrush.StartPoint.ToPoint (), linearGradientBrush.EndPoint.ToPoint ());
}
if (value is CommonRadialGradientBrush radialGradientBrush) {
return new RadialGradientBrush (
new GradientStopCollection (radialGradientBrush.GradientStops.Select (stop => new GradientStop (stop.Color.ToColor (), stop.Offset))));
}
return null;
}
public object ConvertBack (object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException ();
}
public override object ProvideValue (IServiceProvider serviceProvider)
{
return this;
}
}
}
|