Version

Selection

This topic provides information for enabling and using the selection feature in the XamPieChart™ control.

The topic contains the following sections:

Requirements

This article assumes you have already read the Data Binding topic, and uses the code therein as a starting point.

Overview

The XamPieChart supports slice selection by mouse click as the default behavior. You can determine the selected slices by using the SelectedItems property. The selected slices are highlighted as demonstrated in the following image:

SingleSelection

Enabling Selection

There is a property called SelectionMode which is how you set what mode you want the pie chart to use. The default is “Single”. In order to disable selection, set the property to “Manual”.

The following code snippet demonstrates how to disable selection.

In XAML:

<ig:XamPieChart x:Name="pieChart" SelectionMode="Manual" />

In Visual Basic:

pieChart.SelectionMode = SliceSelectionMode.Manual

In C#:

pieChart.SelectionMode = SliceSelectionMode.Manual;

Selection Modes

The pie chart supports three different selection modes.

  • Single

  • Multiple

  • Manual

Single

When the mode is set to single, only one slice can be selected at a time. When you select a new slice the previously selected slice will be deselected and the new one will become selected.

SingleSelection

Multiple

When the mode is set to Multiple, many slices can be selected at once. If you click on a slice, it will become selected and clicking on a different slice will also select that slice leaving the previous slice selected.

MultipleSelection

Manual

When the mode is set to Manual, selection is disabled.

Selection Events

The pie chart has 4 events associated with selection:

The events that end in “Changing” are cancelable events which means you can stop the selection of a slice by setting the event argument property “Cancel” to true. When set to true the associated property will not update and the slice will not become selected. This is useful for scenarios where you want to keep users from being able to select certain slices based on the data inside it.

In XAML:

<ig:XamPieChart x:Name="pieChart" SelectedItemChanging="pieChart_SelectedItemChanging" />

In Visual Basic:

Private Sub pieChart_SelectedItemChanging(sender As Object, e As SelectedItemChangingEventArgs)
	e.Cancel = True
End Sub

In C#:

pieChart.SelectedItemChanging += pieChart_SelectedItemChanging;
void pieChart_SelectedItemChanging(object sender, SelectedItemChangingEventArgs e)
{
    e.Cancel = true;
}

Selecting the Others Slice

For scenarios where you click on the Others slice, the pie chart will return an object called PieSliceOthersContext. This object contains a list of the data items contained within the Others slice.

Related Content