public void ImplicitInheritedStyleForTemplatedElementIsAppliedCorrectlyForContentView() { var controlTemplate = new ControlTemplate(typeof(ContentPresenter)); var rd0 = new ResourceDictionary { new Style(typeof(ContentView)) { Setters = { new Setter { Property = TemplatedView.ControlTemplateProperty, Value = controlTemplate } }, ApplyToDerivedTypes = true } }; var mockApp = new MockApplication(); mockApp.Resources = rd0; mockApp.LoadPage(new ContentPage() { Content = new MyContentView() { Content = new Button() } }); Application.Current = mockApp; var parentView = (ContentView)((ContentPage)mockApp.MainPage).Content; var content = parentView.Content; Assert.That(Equals(content?.Parent, parentView)); }
public void ReplacingResourcesDoesNotOverrideManuallySetProperties() { var label0 = new Label { TextColor = Colors.Pink }; var label1 = new Label(); Assume.That(label0.TextColor, Is.EqualTo(Colors.Pink)); Assume.That(label1.TextColor, Is.EqualTo(null)); var rd0 = new ResourceDictionary { new Style(typeof(Label)) { Setters = { new Setter { Property = Label.TextColorProperty, Value = Colors.Olive } } } }; var rd1 = new ResourceDictionary { new Style(typeof(Label)) { Setters = { new Setter { Property = Label.TextColorProperty, Value = Colors.Lavender } } } }; var mockApp = new MockApplication(); Application.Current = mockApp; mockApp.Resources = rd0; var layout = new StackLayout { Children = { label0, label1, } }; mockApp.LoadPage(new ContentPage { Content = layout }); //Assert.That(label0.TextColor, Is.EqualTo(Color.Pink)); //Assert.That(label1.TextColor, Is.EqualTo(null)); Assert.That(label0.TextColor, Is.EqualTo(Colors.Pink)); Assert.That(label1.TextColor, Is.EqualTo(Colors.Olive)); mockApp.Resources = rd1; Assert.That(label0.TextColor, Is.EqualTo(Colors.Pink)); Assert.That(label1.TextColor, Is.EqualTo(Colors.Lavender)); }