开发者

silverlight 3 listbox item highlight versus selected

开发者 https://www.devze.com 2022-12-27 05:36 出处:网络
I have a listbox and am attempting to select and item in code.Sometime one item is highlighted, that is it is background is colored blue, but a different开发者_如何学Python item has a square blue box

I have a listbox and am attempting to select and item in code. Sometime one item is highlighted, that is it is background is colored blue, but a different开发者_如何学Python item has a square blue box around the it (no highlighting just an hollow outline of a box).

Am I correct in saying one is "highlighted" and one is "selected" and do I have them correctly identified?

Should this be happening... that is these 2 things being out of sync?

Thanks Cody


Just fought this issue. Although the listbox scrollviewer will auto scroll too the selected item in the listbox the first item would have focus and as you discribe keyboard interaction then operated with the first item in the list not eh selected item.

For us the fix was

            this.MyListBox.UpdateLayout(); 
            this.MyListBox.Focus();
            this.MyListBox.SelectedItem = MyObject;
            this.MyListBox.ScrollIntoView(this.MyListBox.SelectedItem);

The order of the actions seems very important.

This was using the ListBox internal scrollviewer.


The item with the blue highlighted background is the SelectedItem. The item with the blue rectangle is the item that currently believes it has the focus.

Ordinarily the Focus rectangle the selected fill are found together because the selected item usually changes with a mouse click which also brings the focus to the same element. However its possible for example that code may change the selected item whilst the ListBox still has the focus. In that case the selected highlight will move the newly selected item but the focus rectangle will remain where it is. (Note to the pendatic I'm describing what appears to the user not how things actually work under the hood).

For an insight on what is going on see the ListBoxItem style in the ListBox Styles and Templates documentation.

0

精彩评论

暂无评论...
验证码 换一张
取 消