diff --git a/.ncrunch/Avalonia.Desktop.v3.ncrunchproject b/.ncrunch/Avalonia.Desktop.v3.ncrunchproject new file mode 100644 index 0000000000..319cd523ce --- /dev/null +++ b/.ncrunch/Avalonia.Desktop.v3.ncrunchproject @@ -0,0 +1,5 @@ + + + True + + \ No newline at end of file diff --git a/.ncrunch/Avalonia.net461.v3.ncrunchproject b/.ncrunch/Avalonia.net461.v3.ncrunchproject new file mode 100644 index 0000000000..319cd523ce --- /dev/null +++ b/.ncrunch/Avalonia.net461.v3.ncrunchproject @@ -0,0 +1,5 @@ + + + True + + \ No newline at end of file diff --git a/Avalonia.v3.ncrunchsolution b/Avalonia.v3.ncrunchsolution index 1b5b0c8930..a2208a9a91 100644 --- a/Avalonia.v3.ncrunchsolution +++ b/Avalonia.v3.ncrunchsolution @@ -2,6 +2,7 @@ tests\TestFiles\**.* + src\Avalonia.Build.Tasks\bin\Debug\netstandard2.0\Avalonia.Build.Tasks.dll True .ncrunch diff --git a/src/Avalonia.Styling/Styling/TypeNameAndClassSelector.cs b/src/Avalonia.Styling/Styling/TypeNameAndClassSelector.cs index cd019e6535..362ac86e50 100644 --- a/src/Avalonia.Styling/Styling/TypeNameAndClassSelector.cs +++ b/src/Avalonia.Styling/Styling/TypeNameAndClassSelector.cs @@ -116,11 +116,9 @@ namespace Avalonia.Styling } } - if (Name != null) + if (Name != null && control.Name != Name) { - return control.Name == Name ? - SelectorMatch.AlwaysThisInstance : - SelectorMatch.NeverThisInstance; + return SelectorMatch.NeverThisInstance; } if (_classes.IsValueCreated && _classes.Value.Count > 0) @@ -130,17 +128,13 @@ namespace Avalonia.Styling var observable = new ClassObserver(control.Classes, _classes.Value); return new SelectorMatch(observable); } - else + else if (!Matches(control.Classes)) { - return Matches(control.Classes) ? - SelectorMatch.AlwaysThisInstance : - SelectorMatch.NeverThisInstance; + return SelectorMatch.NeverThisInstance; } } - else - { - return SelectorMatch.AlwaysThisType; - } + + return Name == null ? SelectorMatch.AlwaysThisType : SelectorMatch.AlwaysThisInstance; } protected override Selector MovePrevious() => _previous; diff --git a/tests/Avalonia.Styling.UnitTests/SelectorTests_Multiple.cs b/tests/Avalonia.Styling.UnitTests/SelectorTests_Multiple.cs index 04b29376b0..ba9b443d92 100644 --- a/tests/Avalonia.Styling.UnitTests/SelectorTests_Multiple.cs +++ b/tests/Avalonia.Styling.UnitTests/SelectorTests_Multiple.cs @@ -85,6 +85,44 @@ namespace Avalonia.Styling.UnitTests Assert.Equal(SelectorMatchResult.NeverThisType, match.Result); } + [Fact] + public void Named_Class_Template_Child_Of_Control() + { + var template = new FuncControlTemplate(parent => + { + return new Border + { + Name = "border", + }; + }); + + var control = new Button + { + Template = template, + }; + + control.ApplyTemplate(); + + var selector = default(Selector) + .OfType