j1rjacob
j1rjacob

Reputation: 430

My <ContentPage.Content> in Xamarin.Forms is not showing up?

When I add toolbar in my Main Page the content page disappear. What should I do to fix this? Can you share insight or point me to links for me to learn. I am just starting with xamarin forms. I been finding the answer the whole day but I can't find one.

<?xml version="1.0" encoding="utf-8" ?>
    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 xmlns:local="clr-namespace:KLConnect"
                 x:Class="KLConnect.MainPage"
                 Title="KLConnect TTM+ Operation">

        <Label x:Name="label"
               FontSize="Medium"
               VerticalOptions="Center" 
               HorizontalOptions="Center" />

        <ContentPage.ToolbarItems>

            <ToolbarItem Text="setting"
                         Order="Primary"
                         Clicked="OnToolbarItemClicked">
                <ToolbarItem.Icon>
                    <OnPlatform x:TypeArguments="FileImageSource"
                                Android="ic_build_white_48dp.png"/>
                </ToolbarItem.Icon>
            </ToolbarItem>

            <ToolbarItem Text="close"
                         Order="Primary"
                         Clicked="OnToolbarItemClicked">
                <ToolbarItem.Icon>
                    <OnPlatform x:TypeArguments="FileImageSource"
                                Android="ic_highlight_off_white_48dp.png"/>
                </ToolbarItem.Icon>
            </ToolbarItem>

            <ToolbarItem Text="help"
                         Order="Primary"
                         Clicked="OnToolbarItemClicked">
                <ToolbarItem.Icon>
                    <OnPlatform x:TypeArguments="FileImageSource"
                                Android="ic_help_outline_white_48dp.png"/>
                </ToolbarItem.Icon>
            </ToolbarItem>

        </ContentPage.ToolbarItems>

        <ContentPage.Resources>
            <ResourceDictionary>
                <Style x:Key="plainButton" TargetType="Button">
                    <Setter Property="BackgroundColor" Value="#eee"/>
                    <Setter Property="TextColor" Value="Black" />
                    <Setter Property="BorderRadius" Value="0"/>
                    <Setter Property="FontSize" Value="40" />
                </Style>
                <Style x:Key="darkerButton" TargetType="Button">
                    <Setter Property="BackgroundColor" Value="#ddd"/>
                    <Setter Property="TextColor" Value="Black" />
                    <Setter Property="BorderRadius" Value="0"/>
                    <Setter Property="FontSize" Value="40" />
                </Style>
                <Style x:Key="orangeButton" TargetType="Button">
                    <Setter Property="BackgroundColor" Value="#E8AD00"/>
                    <Setter Property="TextColor" Value="White" />
                    <Setter Property="BorderRadius" Value="0"/>
                    <Setter Property="FontSize" Value="40" />
                </Style>
            </ResourceDictionary>
        </ContentPage.Resources>

        <ContentPage.Content>
            <Grid x:Name="controlGrid" RowSpacing="1" ColumnSpacing="1">
                <Grid.RowDefinitions>
                    <RowDefinition Height="150" />
                    <RowDefinition Height="*" />
                    <RowDefinition Height="*" />
                    <RowDefinition Height="*" />
                    <RowDefinition Height="*" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Label Text="0" Grid.Row="0" HorizontalTextAlignment="End" VerticalTextAlignment="End" TextColor="White"
            FontSize="60" Grid.ColumnSpan="4" />
                <Button Text = "C" Grid.Row="1" Grid.Column="0"
            Style="{StaticResource darkerButton}" />
                <Button Text = "+/-" Grid.Row="1" Grid.Column="1"
            Style="{StaticResource darkerButton}" />
                <Button Text = "%" Grid.Row="1" Grid.Column="2"
            Style="{StaticResource darkerButton}" />
                <Button Text = "div" Grid.Row="1" Grid.Column="3"
            Style="{StaticResource orangeButton}" />
                <Button Text = "7" Grid.Row="2" Grid.Column="0"
            Style="{StaticResource plainButton}" />
                <Button Text = "8" Grid.Row="2" Grid.Column="1"
            Style="{StaticResource plainButton}" />
                <Button Text = "9" Grid.Row="2" Grid.Column="2"
            Style="{StaticResource plainButton}" />
                <Button Text = "X" Grid.Row="2" Grid.Column="3"
            Style="{StaticResource orangeButton}" />
                <Button Text = "4" Grid.Row="3" Grid.Column="0"
            Style="{StaticResource plainButton}" />
                <Button Text = "5" Grid.Row="3" Grid.Column="1"
            Style="{StaticResource plainButton}" />
                <Button Text = "6" Grid.Row="3" Grid.Column="2"
            Style="{StaticResource plainButton}" />
                <Button Text = "-" Grid.Row="3" Grid.Column="3"
            Style="{StaticResource orangeButton}" />
                <Button Text = "1" Grid.Row="4" Grid.Column="0"
            Style="{StaticResource plainButton}" />
                <Button Text = "2" Grid.Row="4" Grid.Column="1"
            Style="{StaticResource plainButton}" />
                <Button Text = "3" Grid.Row="4" Grid.Column="2"
            Style="{StaticResource plainButton}" />
                <Button Text = "+" Grid.Row="4" Grid.Column="3"
            Style="{StaticResource orangeButton}" />
                <Button Text = "0" Grid.ColumnSpan="2"
            Grid.Row="5" Grid.Column="0" Style="{StaticResource plainButton}" />
                <Button Text = "." Grid.Row="5" Grid.Column="2"
            Style="{StaticResource plainButton}" />
                <Button Text = "=" Grid.Row="5" Grid.Column="3"
            Style="{StaticResource orangeButton}" />
            </Grid>
        </ContentPage.Content>

    </ContentPage>

Upvotes: 0

Views: 1232

Answers (1)

Daniel
Daniel

Reputation: 9521

It's because you have a Label already set at the beginning of your xaml.

Remove this

<Label x:Name="label"
       FontSize="Medium"
       VerticalOptions="Center" 
       HorizontalOptions="Center" />

Upvotes: 1

Related Questions