protected Layout()
{
+ //if things were added in base ctor (through implicit styles), the items added aren't properly parented
+ if (InternalChildren.Count > 0)
+ InternalChildrenOnCollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, InternalChildren));
+
InternalChildren.CollectionChanged += InternalChildrenOnCollectionChanged;
}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
+ xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
+ x:Class="Xamarin.Forms.Xaml.UnitTests.Bz53381">
+ <Grid BackgroundColor="Green">
+ <Label Text="This is my custom control."/>
+ </Grid>
+</ContentView>
\ No newline at end of file
--- /dev/null
+using System;
+using System.Collections.Generic;
+using NUnit.Framework;
+using Xamarin.Forms;
+using Xamarin.Forms.Core.UnitTests;
+
+namespace Xamarin.Forms.Xaml.UnitTests
+{
+ public partial class Bz53381 : ContentView
+ {
+ public Bz53381()
+ {
+ InitializeComponent();
+ }
+
+ public Bz53381(bool useCompiledXaml)
+ {
+ //this stub will be replaced at compile time
+ }
+
+ [TestFixture]
+ class Tests
+ {
+ [SetUp]
+ public void Setup()
+ {
+ Device.PlatformServices = new MockPlatformServices();
+ }
+
+ [TearDown]
+ public void TearDown()
+ {
+ Application.Current = null;
+ Device.PlatformServices = null;
+ }
+
+ [TestCase(true)]
+ [TestCase(false)]
+ public void ControlTemplateAsImplicitAppLevelStyles(bool useCompiledXaml)
+ {
+ Application.Current = new Bz53381App();
+ var view = new Bz53381(useCompiledXaml);
+ Application.Current.MainPage = new ContentPage { Content = view };
+ var presenter = ((StackLayout)view.InternalChildren[0]).Children[1] as ContentPresenter;
+ Assume.That(presenter, Is.Not.Null);
+ var grid = presenter.Content as Grid;
+ Assert.That(grid, Is.Not.Null);
+ Assert.That(grid.BackgroundColor, Is.EqualTo(Color.Green));
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<Application xmlns="http://xamarin.com/schemas/2014/forms"
+ xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
+ xmlns:local="clr-namespace:Xamarin.Forms.Xaml.UnitTests"
+ x:Class="Xamarin.Forms.Xaml.UnitTests.Bz53381App">
+ <Application.Resources>
+ <ResourceDictionary>
+ <Style TargetType="local:Bz53381">
+ <Setter Property="ControlTemplate">
+ <Setter.Value>
+ <ControlTemplate>
+ <StackLayout>
+ <Label Text="This is the control template. A green Grid and Label should be below." />
+ <ContentPresenter />
+ </StackLayout>
+ </ControlTemplate>
+ </Setter.Value>
+ </Setter>
+ </Style>
+ </ResourceDictionary>
+ </Application.Resources>
+</Application>
\ No newline at end of file
--- /dev/null
+using System;
+using System.Collections.Generic;
+
+using Xamarin.Forms;
+
+namespace Xamarin.Forms.Xaml.UnitTests
+{
+ public partial class Bz53381App : Application
+ {
+ public Bz53381App()
+ {
+ InitializeComponent();
+ }
+ }
+}
<Compile Include="Issues\Unreported009.xaml.cs">
<DependentUpon>Unreported009.xaml</DependentUpon>
</Compile>
+ <Compile Include="Issues\Bz53318.xaml.cs">
+ <DependentUpon>Bz53318.xaml</DependentUpon>
+ </Compile>
+ <Compile Include="Issues\Bz53381.xaml.cs">
+ <DependentUpon>Bz53381.xaml</DependentUpon>
+ </Compile>
+ <Compile Include="Issues\Bz53381App.xaml.cs">
+ <DependentUpon>Bz53381App.xaml</DependentUpon>
+ </Compile>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="..\.nuspec\Xamarin.Forms.Debug.targets" />
<EmbeddedResource Include="Issues\Unreported009.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
+ <EmbeddedResource Include="Issues\Bz53318.xaml">
+ <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
+ </EmbeddedResource>
+ <EmbeddedResource Include="Issues\Bz53381.xaml">
+ <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
+ </EmbeddedResource>
+ <EmbeddedResource Include="Issues\Bz53381App.xaml">
+ <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
+ </EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />