Skip to content

Commit

Permalink
fix: Handle NullExtension in XAML code generation
Browse files Browse the repository at this point in the history
  • Loading branch information
kazo0 committed Oct 7, 2020
1 parent 3ef3dfd commit 25a08ce
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4250,6 +4250,11 @@ private string BuildBindingOption(XamlMemberDefinition m, INamedTypeSymbol prope
return $"new RelativeSource(RelativeSourceMode.{resourceName})";
}

if (bindingType.Type.Name == "NullExtension")
{
return "null";
}

// If type specified in the binding was not found, log and return an error message
if (!string.IsNullOrEmpty(bindingType?.Type?.Name ?? string.Empty))
{
Expand Down
3 changes: 2 additions & 1 deletion src/Uno.UI.Tests/App/Xaml/Test_Styles.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,6 @@
</Setter.Value>
</Setter>
</Style>

<Style x:Key="StylesTestNullBasedOn" TargetType="Button" BasedOn="{x:Null}"/>
<Style x:Key="StylesTestBasedOn" TargetType="Button" BasedOn="{StaticResource ButtonStyleWithTemplates1}"/>
</ResourceDictionary>
20 changes: 20 additions & 0 deletions src/Uno.UI.Tests/Windows_UI_Xaml/Given_Explicit_Style.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,25 @@ public void When_Inline_Style()
var tb = page.TestTextBlock;
Assert.AreEqual(38.0, tb.FontSize);
}

[TestMethod]
public void When_Style_BasedOn_Is_Null()
{
var app = UnitTestsApp.App.EnsureApplication();

var button1 = new Button { Style = app.Resources["StylesTestNullBasedOn"] as Style };

app.HostView.Children.Add(button1);
button1.Measure(new Size(1000, 1000));

Assert.IsNull(button1.Style.BasedOn);

var button2 = new Button { Style = app.Resources["StylesTestBasedOn"] as Style };

app.HostView.Children.Add(button2);
button2.Measure(new Size(1000, 1000));

Assert.IsNotNull(button2.Style.BasedOn);
}
}
}

0 comments on commit 25a08ce

Please sign in to comment.