public void ConvertWithNullReturnsNull() { var converter = new ColorToBrushConverter(); var value = converter.Convert(null, typeof(string), null, CultureInfo.CurrentCulture); Assert.IsNull(value); }
public void ConvertBackWithBrushReturnsColor() { var converter = new ColorToBrushConverter(); var expected = Colors.Blue; var actual = converter.ConvertBack(new SolidColorBrush(Colors.Blue), typeof(string), null, CultureInfo.CurrentCulture); Assert.AreEqual(actual, expected); }
public void ConvertWithColorReturnsBrush() { var converter = new ColorToBrushConverter(); var expected = Colors.Blue; var actual = converter.Convert(Colors.Blue, typeof(string), null, CultureInfo.CurrentCulture); Assert.IsInstanceOfType(actual, typeof(SolidColorBrush)); Assert.AreEqual(((SolidColorBrush)actual).Color, expected); }
public object ProvideValue(IServiceProvider serviceProvider) { var stack = serviceProvider.GetService <IAvaloniaXamlIlParentStackProvider>(); var provideTarget = serviceProvider.GetService <IProvideValueTarget>(); var targetType = provideTarget.TargetProperty switch { AvaloniaProperty ap => ap.PropertyType, PropertyInfo pi => pi.PropertyType, _ => null, }; // Look upwards though the ambient context for IResourceHosts and IResourceProviders // which might be able to give us the resource. foreach (var e in stack.Parents) { object value; if (e is IResourceHost host && host.TryGetResource(ResourceKey, out value)) { return(ColorToBrushConverter.Convert(value, targetType)); }
private object GetValue(IStyledElement control, Type targetType) { return(ColorToBrushConverter.Convert(control.FindResource(ResourceKey), targetType)); }
public void ConvertBack_Green() { var converter = new ColorToBrushConverter(); Assert.AreEqual(Colors.Green.ToString(), converter.ConvertBack(new SolidColorBrush(Colors.Green), typeof(Color), null, (CultureInfo)null).ToString()); }
public void ConvertBack_Null() { var converter = new ColorToBrushConverter(); Assert.AreEqual(Colors.Black.ToString(), converter.ConvertBack(null, typeof(Color), null, (CultureInfo)null).ToString()); }
public void Convert_Black() { var converter = new ColorToBrushConverter(); Assert.AreEqual(new SolidColorBrush(Colors.Black).ToString(), converter.Convert(Colors.Black, typeof(Brush), null, (CultureInfo)null).ToString()); }
public void Convert_Null() { var converter = new ColorToBrushConverter(); Assert.AreEqual(ConverterHelper.UnsetValue, converter.Convert(null, typeof(Brush), null, (CultureInfo)null)); }
public void TestConvert2() { var converter = new ColorToBrushConverter(); converter.Convert(null, typeof(Brush), null, null).Should().BeNull(); }
public void SetUp() { Target = new ColorToBrushConverter(); }
private SolidColorBrush Convert(object toConvert) { var converter = new ColorToBrushConverter(); return((SolidColorBrush)converter.Convert(toConvert, typeof(Color), null, CultureInfo.InvariantCulture)); }