Selection
The purpose of this article is to show the basic properties exposed by the RadNavigationView for working with selection.
Using the SelectedItem
The SelectedItem property is used for getting or setting the currently selected item of the RadNavigationView. There are two common cases when accessing the SelectedItem property run-time.
-
When the RadNavigationView is populated with static data (declared in XAML), the SelectedItem property is of type RadNavigationViewItem.
Example 1: Getting the SelectedItem of type RadNavigationViewItem
-
When your RadNavigationView is data bound to a collection of custom objects, the SelectedItem is of the type of the custom object.
Example 2: Getting the SelectedItem of type custom object
Using SelectedValue and SelectedValuePath
The SelectedValue property is used when you have linked the RadNavigationView to a data source, and you want to return a value of one of the properties of the selected object. The SelectedValuePath property provides a way to specify a SelectedValue for the SelectedItem in a RadNavigationView. There are two essential things to remember here:
The SelectedItem property represents an object in the Items collection.
The SelectedValuePath property specifies the path to the property that is used to determine the value of the SelectedValue property.
If SelectedValuePath is not specified, SelectedValue should be equal to SelectedItem.
Examples 3 and 4 demonstrate the usage of the SelectedItem, SelectedValue and SelectedValuePath properties.
Let's assume that you have a business object named NavigationItemModel with one member(property): Title and a RadNavigationView control which is data bound to a list of NavigationItemModel objects.
Example 3: Business object and viewmodel
Example 4: Initializing of RadNavigationView
Figure 1: Result from Example 4 in the Office2016 theme
When you select a NavigationItemModel from the navigation view, the SelectedItem property returns the NavigationItemModel object. However, because the SelectedValuePath is set to Title, the SelectedValue property of the RadNavigationView is set to the Title property of the NavigationItemModel business object.
SelectedValue is supported for the root level items only.
Using the SelectedIndex
Using the SelectedIndex property you can get or set the index of the selected item. For example, by using the SelectedIndex property, you could specify which the default selected item is.
Example 5: Setting SelectedIndex
RadNavigationViewItem Selection Properties
The RadNavigationViewItem exposes two additional properties that help for working with selection. Those are the IsSelected and IsSelectable properties. Both are of type boolean and indicate whether an item is selected and whether it can be selected respectively.
Example 6: Setting the IsSelectable property
The IsSelected and IsSelectable properties can also be bound to properties in your model through a style targetting RadNavigationViewItem.