Browse Source
Merge pull request #10076 from AvaloniaUI/fix-templatebinding-converter-in-multibinding
Fix TemplateBinding with converter inside of MultiBinding
pull/10085/head
Max Katz
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
34 additions and
2 deletions
-
src/Markup/Avalonia.Markup/Data/TemplateBinding.cs
-
tests/Avalonia.Markup.UnitTests/Data/TemplateBindingTests.cs
|
|
|
@ -137,9 +137,9 @@ namespace Avalonia.Data |
|
|
|
templatedParent.GetValue(Property) : |
|
|
|
_target.TemplatedParent; |
|
|
|
|
|
|
|
if (Converter is not null && _targetType is not null) |
|
|
|
if (Converter is not null) |
|
|
|
{ |
|
|
|
value = Converter.Convert(value, _targetType, ConverterParameter, CultureInfo.CurrentCulture); |
|
|
|
value = Converter.Convert(value, _targetType ?? typeof(object), ConverterParameter, CultureInfo.CurrentCulture); |
|
|
|
} |
|
|
|
|
|
|
|
PublishNext(value); |
|
|
|
|
|
|
|
@ -248,6 +248,38 @@ namespace Avalonia.Markup.UnitTests.Data |
|
|
|
// binding is initiated.
|
|
|
|
Assert.Equal(new[] { "foo" }, converter.Values); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_Execute_Converter_Without_Specific_TargetType() |
|
|
|
{ |
|
|
|
// See https://github.com/AvaloniaUI/Avalonia/issues/9766
|
|
|
|
var source = new Button |
|
|
|
{ |
|
|
|
Template = new FuncControlTemplate<Button>((parent, _) => |
|
|
|
new ContentPresenter |
|
|
|
{ |
|
|
|
[~ContentPresenter.IsVisibleProperty] = new MultiBinding |
|
|
|
{ |
|
|
|
Converter = BoolConverters.And, |
|
|
|
Bindings = |
|
|
|
{ |
|
|
|
new TemplateBinding(ContentControl.ContentProperty) |
|
|
|
{ |
|
|
|
Converter = ObjectConverters.IsNotNull |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}), |
|
|
|
}; |
|
|
|
|
|
|
|
source.ApplyTemplate(); |
|
|
|
|
|
|
|
var target = (ContentPresenter)source.GetVisualChildren().Single(); |
|
|
|
|
|
|
|
Assert.False(target.IsVisible); |
|
|
|
source.Content = "foo"; |
|
|
|
Assert.True(target.IsVisible); |
|
|
|
} |
|
|
|
|
|
|
|
private class PrefixConverter : IValueConverter |
|
|
|
{ |
|
|
|
|