XML and Mvx bindings

Our Android user interface will start at MainPage, so we need to add a new file called MainPage.xml, and a new MvxActivity called MainPage.cs. Firstly, add in a new folder called Views; this is where we will be storing our MvxActivities. Let's add a new file called MainPage.cs to the Views folder, and create a new file in the Resources | Layout folder called Main.xml. Our Main.xml is going to start with a LinearLayout and contain four elements: ImageView, TextView, and two Buttons:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:local="http://schemas.android.com/apk/res-auto" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:gravity="center"> 
    <ImageView 
        android:id="@+id/AudioImage" 
        android:layout_width="200dp" 
        android:layout_height="200dp" 
        android:src="@drawable/audio" /> 
    <TextView 
        android:id="@+id/DescriptionText" 
        android:textSize="32sp" 
        android:layout_marginBottom="5dp" 
        android:layout_marginTop="5dp" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        local:MvxBind="Text DescriptionMessage" /> 
    <Button 
        android:id="@+id/AudioPlayerButton" 
        android:layout_width="200dp" 
        android:layout_height="wrap_content" 
        local:MvxBind="Text AudioPlayerTitle; Click AudioPlayerCommand" /> 
    <Button 
        android:id="@+id/ExitButton" 
        android:layout_width="200dp" 
        android:layout_height="wrap_content" 
        local:MvxBind="Text ExitTitle; Click ExitCommand" /> 
</LinearLayout> 

Let's look more closely at the local:Mvxbind properties on the Buttons and TextView. This is where we will set up our bindings to the view-model. We must also add this line:

xmlns:local="http://schemas.android.com/apk/res-auto" 

Does this look familiar?

It is the same as our XAML sheets in Xamarin.Forms; we must import this namespace so we can use the binding properties on our UI elements.

Note

Don't forget to copy all the images into the drawable folder before you try building the project.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.59.231