Xamarin - 使用ContentPage创建UI

时间:2017-01-20 09:11:57

标签: visual-studio xaml xamarin xamarin.forms

我在VisualStudio 2015工作,在那里我创建了Xamarin项目。我想要  将我的旧项目重写为Xamarin.Forms我在创建BottomAppBar时遇到问题。如果Xamarin.Forms有类似于BottomAppBar的东西?我在XAML中的代码是这样的:

<Page
    x:Class="App.View.StartView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App.View"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
>

    <Grid>
        <Grid.Background>
            <ImageBrush
                Stretch="UniformToFill"
                ImageSource="{ThemeResource BackgroundPath}"/>
        </Grid.Background>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="10*"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="1*"/>
            <RowDefinition Height="1*"/>
        </Grid.RowDefinitions>
        <TextBlock
            x:Uid="heading"
            VerticalAlignment="Center"
            HorizontalAlignment="Right"
            Grid.Column="1"
            Grid.Row="0"
            TextAlignment="Right"
            FontFamily="{ThemeResource FontFamily}"
            FontWeight="{ThemeResource FontWeightHeader}"
            FontSize="{ThemeResource FontSizeHeader}"/>

    </Grid>
    <Page.BottomAppBar>
        <CommandBar
            Background="{ThemeResource CommandBarBackgroundBrush}">
            <CommandBar.PrimaryCommands>
                <AppBarButton
                    x:Uid="startAppBarButton"
                    Icon="Play"
                    Command="{ Binding StartCommand}"/>
            </CommandBar.PrimaryCommands>
            <CommandBar.SecondaryCommands>
                <AppBarButton
                    x:Uid="settingsButton"
                    Command="{Binding SettingsCommand}"/>
                <AppBarButton
                    x:Uid="aboutButton"
                    Command="{Binding InfoCommand}"/>
                <AppBarButton
                    x:Uid="helpButton"
                    Command="{Binding HelpCommand}"/>
            </CommandBar.SecondaryCommands>
        </CommandBar>
    </Page.BottomAppBar>
</Page>

现在我没有那么多,但是我试图让观点和我以前的观点一样相似,到目前为止我有:

<?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:ios="clr-namespace:UIKit;assembly=Xamarin.iOS;targetPlatform=iOS"
        xmlns:androidWidget="clr-namespace:Android.Widget;assembly=Mono.Android;targetPlatform=Android"
        xmlns:formsAndroid="clr-namespace:Xamarin.Forms;assembly=Xamarin.Forms.Platform.Android;targetPlatform=Android"
        xmlns:winControls="clr-namespace:Windows.UI.Xaml.Controls;assembly=Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime;targetPlatform=Windows"
        xmlns:local="clr-namespace:NativeViewInsideContentView" 
        x:Class="NativeViewInsideContentView.NativeViewInsideContentViewPage"
        BackgroundImage="Background.png"  
        >


  <StackLayout Margin="20">
      <Button Text="Click Me!"
            HorizontalOptions="Center"
            VerticalOptions="CenterAndExpand" 
                />
  </StackLayout>


</ContentPage>

1 个答案:

答案 0 :(得分:1)

这是让你入门的。从那里,您可以通过谷歌或Bing来解决问题:

Page => ContentPage
Grid => Grid
StackPanel => StackLayout
TextBlock => Label
Page.BottomAppBar => ContentPage.ToolbarItems