IconExtension - return 'Image' (not ImageSource) for MenuItem.Icon

This commit is contained in:
John Colvin committed 2018-12-05 15:40:55 -06:00
1 parent 5763b7fcb4
commit be63415127
1 file changed
+8 -2
@@ -1,10 +1,11 @@
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
using System.Windows.Media;
namespace mbts.ui {
[MarkupExtensionReturnType(typeof(ImageSource))]
class IconExtension : MarkupExtension {
public IconExtension() : this(string.Empty) { }
public IconExtension(string Name) : this(Name, Brushes.Black, 1.0) { }
@@ -28,7 +29,12 @@ namespace mbts.ui {
if (Name == null) return null;
string geo_key = Name + "GeometryKey";
IEnumerable<string> paths = Icons.get_geometric_path(geo_key);
return Icons.create_icon(geo_key, Brush, Pen);
var img_src = Icons.create_icon(geo_key, Brush, Pen);
if (serviceProvider.GetTargetProperty() is DependencyProperty dp) {
if (dp == MenuItem.IconProperty)
return new Image { Source = img_src };
}
return img_src;
}
}
}