Skip to content

SyncfusionExamples/add-context-menu-to-treeview-xamarin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

add-context-menu-to-treeview-xamarin

This repository demonstrates how to add a context menu to nodes in the Syncfusion Xamarin.Forms TreeView control. The sample shows how to implement right-click (desktop) and long-press (mobile) menus that provide node-specific actions like edit, delete, and custom commands.

XAML

<local:SfTreeViewExt x:Name="treeView" ChildPropertyName="SubFiles" NodeSizeMode="Dynamic" NotificationSubscriptionMode="CollectionChange" ItemsSource="{Binding ImageNodeInfo}" AutoExpandMode="AllNodesExpanded">
    <local:SfTreeViewExt.ItemTemplate>
        <DataTemplate>
            <local:CustomGrid x:Name="grid" TreeView="{x:Reference treeView}">
                <local:CustomGrid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="1" />
                </local:CustomGrid.RowDefinitions>
                <Grid RowSpacing="0" Grid.Row="0">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="40" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <Grid Padding="5,5,5,5">
                        <Image Source="{Binding ImageIcon}" VerticalOptions="Center" HorizontalOptions="Center" HeightRequest="35" WidthRequest="35"/>
                    </Grid>
                    <Grid Grid.Column="1" RowSpacing="1" Padding="1,0,0,0" VerticalOptions="Center">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <Label LineBreakMode="NoWrap" TextColor="Black" Text="{Binding ItemName}" VerticalTextAlignment="Center"/>
                    </Grid>
                </Grid>
                <StackLayout Grid.Row="1" HeightRequest="1"/>
            </local:CustomGrid>
        </DataTemplate>
    </local:SfTreeViewExt.ItemTemplate>
</local:SfTreeViewExt>

Requirements to run the demo

To run the demo, refer to System Requirements for Xamarin

Troubleshooting

Path too long exception

If you are facing path too long exception when building this example project, close Visual Studio and rename the repository to short and build the project.

About

How to add a context menu to TreeView in Xamarin.Forms

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages