TreeMap Events in Xamarin TreeMap (SfTreeMap)

18 May 20211 minute to read


The ItemSelected event occurs when an item is selected. The selected leaf node underlying data item and IsSelected boolean property will be passed as arguments to ItemSelectedEventArgs. The IsSelected property indicates whether the item has been selected.

Set the HighlightOnSelection property to true to use the ItemSelected event.


    <treemap:SfTreeMap x:Name="treemap"  DataSource="{Binding PopulationDetails}" WeightValuePath="Population"
                               ColorValuePath="Growth" ItemSelected="Treemap_ItemSelected" HighlightOnSelection="True">

public MainPage()
    treemap.ItemSelected += Treemap_ItemSelected;
    treemap.HighlightOnSelection = true;

private void Treemap_ItemSelected(object sender, TreeMapItemSelectedEventArgs e)
    var selectedItem = e.Item as PopulationDetail;
    bool setSelection = e.IsSelected;


We’ve suggested using DataSource to populate items, when you need Item property value of TreeMapItemSelectedEventArgs.