简体   繁体   中英

Can I design the UI in Xamarin.Forms by using XAML

I'm trying to create a cross platform app using Xamarin.Forms. As far as I know, the UI will be created from the code and the .axml file will be generated automatically.

Can I modify the .axml file to edit the UI? I tried editing but all that comes up is what is written in the code. ie: hello forms

UPDATE

public static Page GetMainPage ()
        {   
            return new simplerow ();
        }

In Xamarin.Forms you can create your pages from markup definitions that are shared across all platforms.

Typically you will write all your content pages using Xamarin.Forms , however you can mix-and-match native pages into an application should you so wish.

These shared common pages, written in Xamarin.Forms , will reside maybe in a PCL project, or a Shared Project so these can then be re-used in the platform-specific projects, each targeting a specific platform OS .

You can write these common pages, either in code , or in XAML . You can even choose to write some pages one way, and some the other if you so choose.

A Xamarin.Forms page is processed at runtime through the interpretation of the page composition that has been created.

Each control that is specified on a page, has its own platform specific renderer, behind the scenes, that will produce output that is targetted to that OS .

When writing Xamarin.Forms pages, for-the-most, you will start to learn a new way of creating pages that is abstracted from the intricacies of creating mobile applications on each different platform OS .

There is therefore no editable .axml that is generated etc as you will write your pages using Xamarin.Forms markup and controls, and even your own or other custom-controls to produce your own application pages.

The following link shows some examples of how to write XAML pages.

The following link shows some examples of how to write from code-behind pages.

Along with the previous answer re: .xaml instead of .axml, you need to remember to change the startup code in app.cs to use your new .xaml form. Replace the "new ContentPage {...};" with "new MyForm();" (where "MyForm" is the name of your shiny new XAML form).

EDIT: Downloaded the project from the dropbox link. Comments below...

I see several issues here. I think you may need to go through the walkthroughs and sample applications provided by Xamarin to get up to speed with the concepts behind XF apps.

First, you are trying to use an Activity as your application's page. In a Xamarin Forms app, it must be a View of some sort, not a platform-specific visual such as Activity.

Second, remove the "test.xml" file from your Android project's Resources/layout folder; while XAML files are indeed XML, they have an 1) have a file extension of .xaml and 2) belong in the shared project.

Here's what you need to do to get your project working: (I'm assuming you're using VS here, under Xamarin Studio, it's slightly different.)

  1. Right-click your "testforms" shared project
  2. Click Add from the context menu and select "New Item"
  3. In the dialog that appears, select "Forms XAML Page" and in the Name area enter a name (such as "MyForm") (If you're using XS, choose "New File" and "Forms ContentPage")
  4. This will add two files to your project: a XAML file containing your layout (eg: MyForm.xaml), and a code-behind file (eg: MyForm.xaml.cs).
  5. Open the XAML file, and modify the Label element so that the Text attribute is

    Text = "Hello, World!"

  6. Modify the body of GetMainPage in your App.cs to the following:

    return new MyForm();

  7. Run the app

Hope this helps!

You got it wrong. Forms are created either through code or XAML. No axml or anything persistent is generated at platform level, everything is done in runtime(XAML is sort of compiled at compile time).

So, modify either code or XAML if you wish to change something. Or, if you need something more demanding, than consider either subclassing an existing Renderer or create you own.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM