我的Xamarin.Forms中的<contentpage.content>没有显示?

时间:2017-03-15 09:33:39

标签: xamarin.forms

当我在主页面中添加工具栏时,内容页面会消失。我该怎么做才能解决这个问题?你可以分享见解或指出我的链接供我学习。我刚开始使用xamarin表格。我一整天都找到了答案,但我找不到答案。

<?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>

1 个答案:

答案 0 :(得分:1)

这是因为您已经在xaml的开头设置了Label

删除此

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