add 'Freeze' prop to BrushExtension

This commit is contained in:
John Colvin committed 2022-01-23 13:09:56 -05:00
1 parent fa9ab9c033
commit f12e8deeab
1 file changed
+10 -10
@@ -2,28 +2,28 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Markup;
using System.Windows.Media;
namespace mbts.ui {
[MarkupExtensionReturnType(typeof(Brush))]
public class BrushExtension : MarkupExtension {
class BrushExtension : MarkupExtension {
public BrushExtension() : this(Colors.Black) { }
public BrushExtension(Color Color) : this(Color, 1.0) { }
public BrushExtension(Color Color, double Opacity) { this.Color = Color; this.Opacity = Opacity; }
[TypeConverter(typeof(ColorTypeConverter))]
[ConstructorArgument("Color")]
public Color Color { get; set; }
public Color Color { get; set; }
[ConstructorArgument("Opacity")]
public double Opacity { get; set; }
public override object ProvideValue(IServiceProvider serviceProvider) {
return new SolidColorBrush(Color) { Opacity = Opacity };
}
}
public double Opacity { get; set; }
public bool Freeze { get; set; }
public override object ProvideValue(IServiceProvider serviceProvider) =>
Freeze ? FrozenBrushCache.get_brush(Color, Opacity) : new SolidColorBrush(Color) { Opacity = Opacity };
}
public class ColorTypeConverter : TypeConverter {
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { return sourceType == typeof(string); }