У меня есть простой Xamarin.Forms
проект с ContentView
, который я хотел бы добавить к ContentPage
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="NamespaceX.Xamarin.Target"
BackgroundColor="Red">
<ContentView.Content>
<Button Text="Welcome to Xamarin.Forms!"
x:Name="ButtonName"
VerticalOptions="Center"
HorizontalOptions="Center"/>
</ContentView.Content>
Вот мой ContentPage
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:NamespaceX.Xamarin"
x:Class="NamespaceX.Xamarin.MainPage">
<local:Target></local:Target>
</ContentPage>
ContentView
действительно добавляется к ContentPage
, поскольку ContentPage
становится красным, но содержимое не отображается.
Когда я добавляю прослушиватель событий SizeChanged
в ContentView
private void View_SizeChanged(object sender, EventArgs e)
{
Debug.WriteLine(this.Width);
Debug.WriteLine(this.Height);
Debug.WriteLine(this.Content.Width);
Debug.WriteLine(this.Content.Height);
}
Ширина и высота ContentView
действительно установлены Width: 360
, Height: 616
, но ширина и высота содержимого -1
.
EDIT
Я только что заметил, что он не работал с Xamarin Live Player, но работал с эмулятором ...