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.MainPage = 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 = Color.Pink }; var label1 = new Label(); Assume.That(label0.TextColor, Is.EqualTo(Color.Pink)); Assume.That(label1.TextColor, Is.EqualTo(Color.Default)); var rd0 = new ResourceDictionary { new Style(typeof(Label)) { Setters = { new Setter { Property = Label.TextColorProperty, Value = Color.Olive } } } }; var rd1 = new ResourceDictionary { new Style(typeof(Label)) { Setters = { new Setter { Property = Label.TextColorProperty, Value = Color.Lavender } } } }; var mockApp = new MockApplication(); Application.Current = mockApp; mockApp.Resources = rd0; var layout = new StackLayout { Children = { label0, label1, } }; mockApp.MainPage = new ContentPage { Content = layout }; //Assert.That(label0.TextColor, Is.EqualTo(Color.Pink)); //Assert.That(label1.TextColor, Is.EqualTo(Color.Default)); Assert.That(label0.TextColor, Is.EqualTo(Color.Pink)); Assert.That(label1.TextColor, Is.EqualTo(Color.Olive)); mockApp.Resources = rd1; Assert.That(label0.TextColor, Is.EqualTo(Color.Pink)); Assert.That(label1.TextColor, Is.EqualTo(Color.Lavender)); }