Skip to content

Commit

Permalink
Added failing test cases for #10856. (#15338)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
grokys committed Apr 13, 2024
1 parent e0d4be0 commit ca520a2
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
14 changes: 14 additions & 0 deletions samples/BindingDemo/GenericMarkupExtension.cs
Original file line number Diff line number Diff line change
@@ -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 changes: 30 additions & 0 deletions samples/BindingDemo/GenericValueConverter.cs
Original file line number Diff line number Diff line change
@@ -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 changes: 15 additions & 0 deletions samples/BindingDemo/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

0 comments on commit ca520a2

Please sign in to comment.