Xamarin 如何在NavigationDrawer的FrameLayout中获取按钮

Xamarin 如何在NavigationDrawer的FrameLayout中获取按钮,xamarin,xamarin.android,Xamarin,Xamarin.android,我是NavigationDrawer的新手,下面的代码正在运行 但是,如何在homeLayout.axml中获取按钮,该按钮在下面的代码之后如HomeFragment.cs中所示膨胀 ft.Add(Resource.Id.HomeFrameLayout, new HomeFragment()); ft.Commit(); 1) 我需要将eventHandler添加到homeLayout.axml中的btn:btn产品中 -在何处添加以下代码 我需要向设置代码中添加什么来获取BTN产

我是NavigationDrawer的新手,下面的代码正在运行

但是,如何在homeLayout.axml中获取按钮,该按钮在下面的代码之后如HomeFragment.cs中所示膨胀

   ft.Add(Resource.Id.HomeFrameLayout, new HomeFragment());
   ft.Commit();
1) 我需要将eventHandler添加到homeLayout.axml中的btn:btn产品中
-在何处添加以下代码
我需要向设置代码中添加什么来获取BTN产品并为此按钮添加事件??

  SetContentView (Resource.Layout.????);
  Btn = FindViewById<Button>(Resource.Id.BtnGM);
  Btn.Click += Btn_Click1;
----------homeplayout.axml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff">
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:background="#ffffff"
        android:orientation="vertical">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#ff46a2fd"
            android:text="Home"
            android:textSize="22dp"
            android:textStyle="bold"
            android:typeface="sans"
            android:gravity="center"
            android:layout_gravity="center"
            android:layout_centerInParent="true" />
        <Button
            android:id="@+id/btnProducts"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_margin="3dp"
            android:layout_marginTop="3dp"
            android:background="#307FC1"
            android:text="merchant"
            android:layout_alignParentBottom="true"
            android:textColor="#ffffff" />
    </LinearLayout>
</RelativeLayout>

在HomeFragment.cs的OnCreateView方法中添加以下内容(在视图声明和返回声明之间):

public class NaviDrawerActivity : AppCompatActivity
 {

    private SupportToolbar toolbar;
    DrawerLayout drawerLayout;     

   protected override void OnCreate(Bundle savedInstanceState)
   {
      base.OnCreate(savedInstanceState);

      SetContentView(Resource.Layout.NaviDrawer);          
      drawerLayout = FindViewById<DrawerLayout>(Resource.Id.drawer_layout);

      //--- Init toolbar
      toolbar = FindViewById<SupportToolbar>(Resource.Id.app_bar);

      SetSupportActionBar(toolbar);
      SupportActionBar.SetTitle(Resource.String.app_name);
      SupportActionBar.SetDisplayHomeAsUpEnabled(true);
      SupportActionBar.SetDisplayShowHomeEnabled(true);

     //--- Attach item selected handler to navigation view

     var navigationView = FindViewById<NavigationView>(Resource.Id.nav_view);
     navigationView.NavigationItemSelected += NavigationView_NavigationItemSelected;

     //-- Create ActionBarDrawerToggle button and add it to the toolbar

    var drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, Resource.String.open_drawer, Resource.String.close_drawer);
    drawerLayout.SetDrawerListener(drawerToggle);
    drawerToggle.SyncState();

     //--load default home screen

      var ft = FragmentManager.BeginTransaction();
       ft.AddToBackStack(null);

       ft.Add(Resource.Id.HomeFrameLayout, new HomeFragment());
       ft.Commit();
   }


  //---define custom title text

  protected override void OnResume()
  {
       SupportActionBar.SetTitle(Resource.String.app_name);
       base.OnResume();
  }
 class HomeFragment: Fragment
    {
        public override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);           
        }

     public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle     savedInstanceState)
        {
          View view = inflater.Inflate(Resource.Layout.homeLayout, container, false);
          return view;
       }
    }
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff">
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:background="#ffffff"
        android:orientation="vertical">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#ff46a2fd"
            android:text="Home"
            android:textSize="22dp"
            android:textStyle="bold"
            android:typeface="sans"
            android:gravity="center"
            android:layout_gravity="center"
            android:layout_centerInParent="true" />
        <Button
            android:id="@+id/btnProducts"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_margin="3dp"
            android:layout_marginTop="3dp"
            android:background="#307FC1"
            android:text="merchant"
            android:layout_alignParentBottom="true"
            android:textColor="#ffffff" />
    </LinearLayout>
</RelativeLayout>
var btnProducts = view.FindViewById<Button>(Resource.Id.btnProducts);
btnProducts.Click += btnProducts_Click;
public void btnProducts_Click(object sender, EventArgs e)
{
    // Action you want to take upon button click
}