Browse Source
Merge pull request #6815 from AvaloniaUI/fixes/static-resource-brush-converter
Fixes/static resource brush converter
pull/7003/head
Dan Walmsley
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
33 additions and
0 deletions
-
src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/StaticResourceExtension.cs
-
tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/StaticResourceExtensionTests.cs
|
|
|
@ -5,6 +5,7 @@ using Avalonia.Controls; |
|
|
|
using Avalonia.Markup.Data; |
|
|
|
using Avalonia.Markup.Xaml.Converters; |
|
|
|
using Avalonia.Markup.Xaml.XamlIl.Runtime; |
|
|
|
using Avalonia.Styling; |
|
|
|
|
|
|
|
namespace Avalonia.Markup.Xaml.MarkupExtensions |
|
|
|
{ |
|
|
|
@ -33,6 +34,11 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions |
|
|
|
_ => null, |
|
|
|
}; |
|
|
|
|
|
|
|
if (provideTarget.TargetObject is Setter setter) |
|
|
|
{ |
|
|
|
targetType = setter.Property.PropertyType; |
|
|
|
} |
|
|
|
|
|
|
|
// 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) |
|
|
|
|
|
|
|
@ -512,6 +512,33 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions |
|
|
|
var brush = (ISolidColorBrush)border.Background; |
|
|
|
Assert.Equal(0xff506070, brush.Color.ToUint32()); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Automatically_Converts_Color_To_SolidColorBrush_From_Setter() |
|
|
|
{ |
|
|
|
using (StyledWindow()) |
|
|
|
{ |
|
|
|
var xaml = @"
|
|
|
|
<Window xmlns='https://github.com/avaloniaui'
|
|
|
|
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
|
|
|
|
<Window.Resources> |
|
|
|
<Color x:Key='color'>#ff506070</Color> |
|
|
|
</Window.Resources> |
|
|
|
<Window.Styles> |
|
|
|
<Style Selector='Button'> |
|
|
|
<Setter Property='Background' Value='{StaticResource color}'/> |
|
|
|
</Style> |
|
|
|
</Window.Styles> |
|
|
|
<Button Name='button'/> |
|
|
|
</Window>";
|
|
|
|
|
|
|
|
var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml); |
|
|
|
var button = window.FindControl<Button>("button"); |
|
|
|
var brush = (ISolidColorBrush)button.Background; |
|
|
|
|
|
|
|
Assert.Equal(0xff506070, brush.Color.ToUint32()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private IDisposable StyledWindow(params (string, string)[] assets) |
|
|
|
{ |
|
|
|
|