The Issue
Using the Factory Commander, I noticed some strange behavior.
I opened a folder with more items than can be displayed on the screen on the left side. Then I scrolled to the last item of the list and switched to the right list. There, I moved up or down one folder level (goto parent or child folder). The item list on the right side gets refreshed, and, to my surprise, the list on the left side scrolled up. It did so every time I moved up or down one level until the first item of the left list was displayed. Switch back to the left list, the list scrolls down to the focused last item itself.
I was able to reproduce this behavior with a simple Windows Store app having just two ListView
controls, without any additional logic. So it seems to be a general issue, independent from the Factory Commander implementation.
The Solution
It took me some time, but after a while I found the (or one of the possible) solution. By default, the IsTabStop
property of a ListView
is set to false
. Changing it to true
solved my issue. It seems that setting this property enables the ListView
to keep the focus even if there are no items in the list.
In WPF, there are two different properties: Focusable
and IsTabStop
.
Focusable
“gets or sets a value that indicates whether the element can receive focus“, while IsTabStop
“gets or sets a value that indicates whether a control is included in tab navigation.”
The Control
(base class of ListView
) in WPF contains both properties, while the Control
implementation for Windows Store apps lacks of the Focusable
property. Seems the “.NET for Windows Store apps” framework team at MS decided that this property is “not related to developing Windows Store apps”.
Links
2,000 Things You Should Know About WPF; explanation of Focusable
and IsTabStop
in WPF