silverlight 3 listbox item highlight versus selected - silverlight

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 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.

Related

WPF Expander MouseOver Issue

I have Expander control which shows list of items when you expand it. If i do mouse hover over on header, it will expand it.
I need following things which needs to be implemented from code behind or in xaml.
1) if user do mouseover on expander header and press enter key then by default first item from the list needs to be selected.
2) if user do mouseover on one of the item of list and press enter key then we have to select perticular item. - I already have this implemented.
My question is I am able to capture enter key event in code behind but how would I know that user has mouse over on expander header or expander item as I have to do two diff things.
Thanks
Dee
You can use Mouse.DirectlyOver to get the element it's over, you can then walk up the tree to see if you are in your relevant scope (i.e. find the expander/header), or you can check the IsMouseOver of the relevant controls instead, which should also return true if the mouse is over a child element.

TreeView - Set default select item and highlight (blue) this item

When I create a TreeView Control, insert several items, then I use TVM_SELECTITEM to select an default item. But this item is not highlighted by blue color. Later, if I use mouse or keyboard to select an item, it will be highlighted.
So how to make the default item being highlighted?
This is the function and parameters I used:
SendMessage(hTreeView, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hItem);
I just found I just need to set focus on TreeView control and it works.
But how do I have a gray highlight on the item even when TreeView lose the focus, when users select some options, like the following picture:
Since you figured out the answer to your original question, I'll answer your second:
I just found I just need to set focus on TreeView control and it
works.
But how do I have a gray highlight on the item even when TreeView lose
the focus, when users select some options, like the following picture:
Give your TreeView control the TVS_SHOWSELALWAYS window style. (Incidentally, the screenshot you show uses a ListView control, not a TreeView control. ListView controls have an equivalent LVS_SHOWSELALWAYS style.)

ComboBox selected item text disappears when scrolling listbox

I have Combo boxes inside a list box and whenever the list box is scrolled and the combo box is scrolled off of the screen the list box is firing a selection change event on the combo box and setting the selected index of the combo box to null.
If I scroll back and forth multiple times you will see the selected item display and be removed by scrolling the list back and forth.
Does anyone have an idea on ow to fix this? I need the combo box to retain the selected index.
I have even changed the collection that holds the Combo-box data to a list from an observable collection and it still does the same thing.
I am using silver light v4, .net 4
Thanks...
This is probably a result of the default virtualising nature of the ListBox. As items scroll off the displayed the items are actually removed from the Visual Tree. If you don't have too many items in the list set the ItemsPanel property of the ListBox to an ItemsPanelTemplate containing a simple StackPanel.
Better would be to cease using the selection change event in this scenario, use a binding on the SelectedItem property instead.
I had the same issue, but with a datagrid.
I tried this (preferable solution), but it didnt work for me.
Silverlight ComboBox and SelectedItem
So i had to go with this....
http://forums.silverlight.net/post/396922.aspx

z order of surface listbox item

I am trying to bring the focus on the clicked item of the surface listbox. For WPF I had a similar post and it worked after setting the trigger property of .
The full xaml code is available at http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/5d486826-9a72-4769-bd09-ff6977e16c30/#cd2cd9af-abbf-40ca-9e30-4684ee2a2eb2
I tried doing the same in the xaml code for a surface button which is put as item in surface listbox, nothing happens. Basically, my listbox contains surface buttons and when any button is clicked, it scales up i.e. the size of it increases. The only issue is that next item overlaps the scaled item because of the z-order issue. For the normal WPF listbox and button control above code did the trick but its not happening for surface application.
Would appreciate any help/directions in this issue.
Got it working.. Had posted on MSDN and it finally worked by setting the zIndex of the surfaceListbox instead of the content of the item which was a surfacebutton.
http://social.msdn.microsoft.com/Forums/en-US/surfaceappdevelopment/thread/970877bd-2960-4f0e-a203-1d357bbd55ce/#4a08e54b-5055-4a66-ad75-762ee88ef303

WPF popup on ListBoxItem

I have a MiniToolbar popup that shows up at Mouseover on a ListBoxItem, it needs to show just under the item.
(a MouseOver trigger also sets the IsSelected property on the items)
I tried two options :
define the popup on the items DataTemplate
define the popup on the ControlTemplate for the ListBoxItem
Both options work fine, however I was wondering if the popup was recreated each time ??
(please advise)
I think it would be better to define the popup in the ControlTemplate of the containing ListBox rather than the ListBoxItem ?
I tried this, but could not find the binding expression for placement property relative to the SelectedItem (it shows up at the bottom of the ListBox, not bottom of ListBoxItem).
Any suggestions ?
thanks in advance.
Michael.
The popup is created one time for each list box item in both cases.
I would not suggest that you use single popup for all items in the CotnrolTemplate for the list box because it significantly complicates things. But if you still want to do so, you can set Placement="Custom" on you popup and specify CustomPopupPlacementCallback. In that callback you can calculate the placement using the position of currently selected item.

Resources