Hierarchical Collection - Select first child when selecting main item

Hey,

is it possible to select the first child when clicking on the main item?


Example:

+ MainItem 1
++ ChildItem 1.1
++ ChildItem 1.2
+ MainItem 2
++ ChildItem 2.1
++ ChildItem 2.2
+ MainItem 3
+ MainItem 4


When I click on MainItem 2 I want the control to select ChildItem 2.1 without showing the ContentView for MainItem 1.

Is this possible?


Thanks.


Possible Workaround: ItemType.Button with an empty command.


3 Replies 1 reply marked as answer

BV Brundha Velusamy Syncfusion Team February 19, 2024 02:46 PM UTC

Hi Boon,


We have developed a sample solution to address your requirement in the SfNavigationDrawer control by utilizing the ItemClicked event as shown in the provided code snippet.


Please refer the below code snippet for this,

private void navigationDrawer_ItemClicked(object sender, Syncfusion.UI.Xaml.NavigationDrawer.NavigationItemClickedEventArgs e)

{

    var clickedItem = e.Item.Header;

    if (clickedItem != null )

    {

        if (clickedItem.Equals("Explore") || clickedItem.Equals("Item1"))

        {

            labelContent.Content = "Item1";

        }

       

        else if (clickedItem.Equals("My music") || clickedItem.Equals("Song1"))

        {

            labelContent.Content = "Song1";

        }

       

}


For your convenience, we have included the sample as an attachment. Kindly review the attached file and inform us if you have any concerns.


Regards,

Brundha V


Attachment: NavigationDrawerSample_79476520.zip

Marked as answer

BO Boon February 19, 2024 04:00 PM UTC

Oh man, so easy :-( Thank you!



PR Preethi Rajakandham Syncfusion Team February 20, 2024 06:08 AM UTC

Hi Boon,

You're welcome. Please let us know if you require any further assistance on this, we will be happy to assist you. 

Regards,

Preethi R



Loader.
Up arrow icon