|
@@ -458,6 +458,23 @@ namespace Avalonia.Markup.Xaml.UnitTests
|
|
|
Assert.Equal(RuntimeXamlDiagnosticSeverity.Warning, warning.Severity);
|
|
|
Assert.Equal("AVLN2208", warning.Id);
|
|
|
}
|
|
|
+
|
|
|
+ [Fact]
|
|
|
+ public void Type_Converters_Should_Work_When_Specified_With_Attributes_On_Avalonia_Properties()
|
|
|
+ {
|
|
|
+ using (UnitTestApplication.Start(TestServices.StyledWindow))
|
|
|
+ {
|
|
|
+
|
|
|
+ var parsed = (XamlIlClassWithTypeConverterOnAvaloniaProperty)
|
|
|
+ AvaloniaRuntimeXamlLoader.Parse(@"
|
|
|
+<XamlIlClassWithTypeConverterOnAvaloniaProperty
|
|
|
+ xmlns='clr-namespace:Avalonia.Markup.Xaml.UnitTests;assembly=Avalonia.Markup.Xaml.UnitTests'
|
|
|
+ MyProp='a,b,c'/>",
|
|
|
+ typeof(XamlIlBugTestsEventHandlerCodeBehind).Assembly);
|
|
|
+
|
|
|
+ Assert.Equal((IEnumerable<string>)["a", "b", "c"], parsed.MyProp.Select(x => x.Value));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public class XamlIlBugTestsEventHandlerCodeBehind : Window
|
|
@@ -554,4 +571,38 @@ namespace Avalonia.Markup.Xaml.UnitTests
|
|
|
{
|
|
|
public int Count { get; set; }= 5;
|
|
|
}
|
|
|
+
|
|
|
+ public class XamlIlClassWithTypeConverterOnAvaloniaProperty : AvaloniaObject
|
|
|
+ {
|
|
|
+ public class MyType(string value)
|
|
|
+ {
|
|
|
+ public string Value => value;
|
|
|
+ }
|
|
|
+
|
|
|
+ public class MyTypeConverter : TypeConverter
|
|
|
+ {
|
|
|
+ public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
|
|
|
+ {
|
|
|
+ return sourceType == typeof(string);
|
|
|
+ }
|
|
|
+
|
|
|
+ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
|
|
|
+ {
|
|
|
+ if (value is string s)
|
|
|
+ return s.Split([','], StringSplitOptions.RemoveEmptyEntries).Select(x => new MyType(x.Trim()));
|
|
|
+ return base.ConvertFrom(context, culture, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static readonly StyledProperty<IEnumerable<MyType>> MyPropProperty = AvaloniaProperty.Register<XamlIlClassWithTypeConverterOnAvaloniaProperty, IEnumerable<MyType>>(
|
|
|
+ "MyProp");
|
|
|
+
|
|
|
+ [TypeConverter(typeof(MyTypeConverter))]
|
|
|
+ public IEnumerable<MyType> MyProp
|
|
|
+ {
|
|
|
+ get => GetValue(MyPropProperty);
|
|
|
+ set => SetValue(MyPropProperty, value);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|