TreeMap Events in Xamarin TreeMap (SfTreeMap)

18 May 20211 minute to read

ItemSelected

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.

<Grid>

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

</Grid>
public MainPage()
{
    InitializeComponent();
    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;
}

NOTE

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