I bound Selected Item of ListView with my viewmodel property SelectedLayout
and I have changed SelectedLayout
from code behind. The Selected Item is changing properly But focus is not coming to the selected item. It is clear when I press enter. Focus is at button where it was before setting SelectedLayout
. How can I get Focus to the selected Item in windows 10 UWP?
Asked
Active
Viewed 771 times
0

Alias Varghese
- 2,104
- 3
- 24
- 52
1 Answers
3
Just changing the value of bound property does not automatically change the focus to the corresponding element. It is done by design, as in many cases you do not need to change focus, just to update the value of the control. So what you need to do is to implement the logic of changing focus in your MVVM code.
To do that, the good practice would be to use Attached Property as outlined here: Set focus on textbox in WPF from view model (C#). In this manner, you can bind the IsFocused attached property of your controls to your ViewModel, and then implement any focusing logic in the ViewModel.

Community
- 1
- 1

Dmitri Soshnikov
- 727
- 4
- 7