How to add a sub menu to SfNavigationDrawer in Xamarin.Android?
Sub menu can be added to SfNavigationDrawer using SfTreeView. Check the following steps to add the sub menu to drawer.
Step 1: Create a Model and ViewModel classes for SfTreeView, which is used in SfNavigationDrawer.
Step 2: Create a list of collections in the ViewModel class, and add data to Treeview.
Step 3: Set the collection to the Drawer content view.
The following code sample demonstrates how to create an SfTreeView inside the NavigationDrawer.
C#
MainActivity.cspublic class MainActivity : Activity { SfNavigationDrawer navigationDrawer; protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); navigationDrawer = new SfNavigationDrawer(this); navigationDrawer.DrawerWidth = 300; FrameLayout ContentFrame = new FrameLayout(this); ContentFrame.LayoutParameters = new Android.Views.ViewGroup.LayoutParams(Android.Views.ViewGroup.LayoutParams.MatchParent, Android.Views.ViewGroup.LayoutParams.MatchParent); Button button = new Button(this); button.LayoutParameters = new Android.Views.ViewGroup.LayoutParams(Android.Views.ViewGroup.LayoutParams.MatchParent, Android.Views.ViewGroup.LayoutParams.WrapContent); button.Gravity = Android.Views.GravityFlags.Center; button.TextAlignment = Android.Views.TextAlignment.Center; button.Text = "Click_To_Open_Drawer"; button.Click += Button_Click; SfTreeView treeView = new SfTreeView(this); FileManagerViewModel viewModel = new FileManagerViewModel(); treeView.AutoExpandMode = AutoExpandMode.AllNodesExpanded; treeView.ChildPropertyName = "SubFolder"; treeView.ItemsSource = viewModel.Folders; treeView.Adapter = new NodeImageAdapter(); treeView.SelectionBackgroundColor = Color.ParseColor("#3A3A3A"); treeView.SelectionForegroundColor = Color.White; navigationDrawer.DrawerContentView = treeView; navigationDrawer.DrawerContentView.SetBackgroundColor(Color.Black); ContentFrame.AddView(button); navigationDrawer.ContentView = ContentFrame; SetContentView(navigationDrawer); } private void Button_Click(object sender, System.EventArgs e) { navigationDrawer.IsOpen = true; } }
Output:
You can download the sample in the following link: Sample
Conclusion
I hope you enjoyed learning about how to add a sub menu to SfNavigationDrawer in Xamarin.Android.
You can refer to our Xamarin.Android Navigation Drawer feature tour page to know about its other groundbreaking feature representations. You can also explore our documentation to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!