Dela via


ListViewBase.SingleSelectionFollowsFocus Property

Definition

Gets or sets a value that indicates whether item selection changes when keyboard focus changes.

public:
 property bool SingleSelectionFollowsFocus { bool get(); void set(bool value); };
bool SingleSelectionFollowsFocus();

void SingleSelectionFollowsFocus(bool value);
public bool SingleSelectionFollowsFocus { get; set; }
var boolean = listViewBase.singleSelectionFollowsFocus;
listViewBase.singleSelectionFollowsFocus = boolean;
Public Property SingleSelectionFollowsFocus As Boolean
<listViewBase SingleSelectionFollowsFocus="bool" />

Property Value

Boolean

bool

true if item selection changes when keyboard focus changes; otherwise, false. The default is true.

Windows requirements

Device family
Windows 10 Anniversary Edition (introduced in 10.0.14393.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v3.0)

Remarks

This property is ignored if the list view's SelectionMode property is not set to Single.

By default, when a list view is configured for single selection, when the user moves keyboard focus to an item, the focused item is also selected. For example, if keyboard focus is moved from the first item to the second item, the SelectedIndex property is updated from 0 to 1.

Set this property to false to let a user move focus without the item selection following. For example, if each selection change causes significant UI updates, you might prefer to let the user move focus to a non-adjacent item and then press enter to update selection.

Version compatibility

The SingleSelectionFollowsFocus property is not available prior to Windows 10, version 1607. If your app’s 'minimum platform version' setting in Microsoft Visual Studio is less than the 'introduced version' shown in the Requirements block later in this page, you must design and test your app to account for this. For more info, see Version adaptive code.

To avoid exceptions when your app runs on previous versions of Windows 10, do not set this property in XAML or use it without performing a runtime check. This example shows how to use the ApiInformation class to check for the presence of this property before you set it.

<ListView x:Name="listView1" Loaded="ListView_Loaded"/>
private void ListView_Loaded(object sender, RoutedEventArgs e)
{
    if (ApiInformation.IsPropertyPresent("Windows.UI.Xaml.Controls.ListViewBase", "SingleSelectionFollowsFocus"))
    {
        listView1.SingleSelectionFollowsFocus = false;
    }
}

Applies to