Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Xamarin Forms - MasterDetailPage, ContentPage VS Fragments

$
0
0

Is it possible to use a Resource layout into a ContentPage's Content?
I was using fragments and made a .axml with a few components in it and would like to reuse that same one as the first NavigationPage.

Can we convert a fragment or its layout into a "Xamarin.Forms.View"?

The important line is this one:

Content = inflater.Inflate(Resource.Menu.main_activity_actions, context)

Part of my code below:

protected override void OnCreate (Bundle bundle){
        base.OnCreate (bundle);
        Xamarin.Forms.Forms.Init (this, bundle);
        SetPage (GetMainPage (this));
}
public static Page GetMainPage(Context context)
{
        LayoutInflater inflater = (LayoutInflater)context.GetSystemService (Context.LayoutInflaterService);
        return MDPage = new MasterDetailPage {
        Master = new ContentPage {
            Title = "Master",
            BackgroundColor = Color.Silver,
            Icon = "slideout.png",
            Content = new StackLayout {
                Padding = new Thickness(5, 50),
                Children = { Link(context.GetString(Resource.String.dashboard)), Link(context.GetString(Resource.String.submit_claim)), Link(context.GetString(Resource.String.claim_history)) }
            },
        },
        Detail = new NavigationPage(new ContentPage {
            Title = context.GetString(Resource.String.dashboard),
            Content = inflater.Inflate(Resource.Menu.main_activity_actions, context)
                //Activity.SetContentView(Resource.Menu.main_activity_actions)//Xamarin.Forms.//new Label { Text = "test" }
        })
    };
}

The .axml file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffffffff">
    <TextView
        android:text="@string/dashboard"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:id="@+id/txvTitle1"
        android:textColor="#ff000000" />
    <barchart.BarChartView
        android:id="@+id/brcHome"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_width="fill_parent"
        android:layout_height="180dp" />
    <View
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:layout_marginTop="5dp"
        android:layout_marginBottom="5dp"
        android:background="@android:color/darker_gray" />
    <TextView
        android:text="@string/recent_activities"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:id="@+id/txfTitle2"
        android:textColor="#ff000000" />
    <Button
        android:text="Button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/button1" />
</LinearLayout>

Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>