Op Englesch liesen

Deelen iwwer

Xamarin.Forms Editor Tutorial

Create a editor

To complete this tutorial you should have Visual Studio 2019 (latest release), with the Mobile development with .NET workload installed. In addition, you will require a paired Mac to build the tutorial application on iOS. For information about installing the Xamarin platform, see Installing Xamarin. For information about connecting Visual Studio 2019 to a Mac build host, see Pair to Mac for Xamarin.iOS development.

  1. Launch Visual Studio, and create a new blank Xamarin.Forms app named EditorTutorial.

    Wichteg

    The C# and XAML snippets in this tutorial requires that the solution is named EditorTutorial. Using a different name will result in build errors when you copy code from this tutorial into the solution.

    For more information about the .NET Standard library that gets created, see Anatomy of a Xamarin.Forms application in the Xamarin.Forms Quickstart Deep Dive.

  2. In Solution Explorer, in the EditorTutorial project, double-click MainPage.xaml to open it. Then, in MainPage.xaml, remove all of the template code and replace it with the following code:

    XAML
    <?xml version="1.0" encoding="utf-8"?>
    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 x:Class="EditorTutorial.MainPage">
        <StackLayout Margin="20,35,20,20">
            <Editor Placeholder="Enter multi-line text here"
                    HeightRequest="200" />
        </StackLayout>
    </ContentPage>
    

    This code declaratively defines the user interface for the page, which consists of an Editor in a StackLayout. The Editor.Placeholder property specifies the placeholder text that's shown when the Editor is first displayed. In addition, the HeightRequest property specifies the height of the Editor in device-independent units.

  3. In the Visual Studio toolbar, press the Start button (the triangular button that resembles a Play button) to launch the application inside your chosen remote iOS simulator or Android emulator:

    Screenshot of an Editor on iOS and Android

    Notiz

    While Android indicates the height of the Editor, iOS does not.

    In Visual Studio, stop the application.