Forráskód Böngészése

Added failing test cases for #10856. (#15338)

This issue only shows up when using the cecil backend for XamlX and so can't easily be tested with unit tests. The easiest way to test it is to add it to a sample project, `BindingDemo` is as good as anywhere I think.
Steven Kirk 1 éve
szülő
commit
ca520a2332

+ 14 - 0
samples/BindingDemo/GenericMarkupExtension.cs

@@ -0,0 +1,14 @@
+using System;
+using Avalonia.Markup.Xaml;
+
+namespace BindingDemo;
+
+internal class GenericMarkupExtension<T> : MarkupExtension
+{
+    public T Value { get; set; }
+
+    public override object ProvideValue(IServiceProvider serviceProvider)
+    {
+        return $"{Value?.GetType().Name}: {Value}";
+    }
+}

+ 30 - 0
samples/BindingDemo/GenericValueConverter.cs

@@ -0,0 +1,30 @@
+using System;
+using System.Globalization;
+using Avalonia.Data.Converters;
+
+#nullable enable
+
+namespace BindingDemo;
+
+public class GenericValueConverter<T> : IValueConverter
+{
+    public GenericValueConverter()
+    {
+        
+    }
+
+    public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
+    {
+        if (value is T)
+        {
+            return $"{typeof(T).Name}: {value}";
+        }
+
+        return null;
+    }
+
+    public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
+    {
+        throw new NotSupportedException();
+    }
+}

+ 15 - 0
samples/BindingDemo/MainWindow.xaml

@@ -120,5 +120,20 @@
         <Button Content="Command Method Do" Command="{Binding Do}" x:Name="ToDo"/>
       </StackPanel>
     </TabItem>
+    <TabItem Header="Advanced">
+      <TabItem.Resources>
+        <local:GenericValueConverter x:Key="BrushConverter" x:TypeArguments="SolidColorBrush"/>
+      </TabItem.Resources>
+      <StackPanel>
+        <!-- Tests for #10856  -->
+        <TextBlock Text="{local:GenericMarkupExtension, Value=Red, x:TypeArguments=Color}"/>
+        <TextBlock HorizontalAlignment="Left"
+                   Text="{Binding $self.Background, Converter={StaticResource BrushConverter}}">
+          <TextBlock.Background>
+            <SolidColorBrush Color="Yellow"/>
+          </TextBlock.Background>
+        </TextBlock>
+      </StackPanel>
+    </TabItem>
   </TabControl>
 </Window>