Hi,
I'm trying to programmatically set the selected item in a gallery tool. It works when I look at the properties in the debugger. This doesn't seem to do much else, however: The ItemSelected event is not triggered, and when I click on the button to see the gallery items, the one I set as selected is not highlighted.
Is there some kind of magic involved in doing this, or is it a bug? My gallery in XAML is patterned after the one from the XamFeatureBrowser - nothing particularly fancy (I want to use it as a theme selector.)
Thanks,Michel
You probably need to set the ItemBehavior to StateButton. Otherwise it will just act like a button which will invoke the ItemClicked event and not show any selection state.
Andrew Smith"] You probably need to set the ItemBehavior to StateButton. Otherwise it will just act like a button which will invoke the ItemClicked event and not show any selection state.
Hi Andrew,
It was already set to StateButton. I also tried Button, just in case. No event gets triggered when assigning SelectedItem programmatically, in both cases. I tried these events: ItemSelected, ItemActivated, ItemClicked. Works fine when selecting a gallery item using the mouse, but that's not good enough here (on startup, I read the last theme used from the config file and need to set it programmatically.)
Any idea?
Thanks for the feedback. Setting the SelectedItem should probably be setting the IsSelected of the associated item. Maybe we can address this in a future build.
OK, that works. I was doing this:
ThemesGallery.SelectedItem = _themeItem
(Where "_themeItem" is a GalleryItem object obtained through a For Each construct)
I reworked the code a little and now I do this:
ThemesGallery.Items(_themesIndex).IsSelected = True
...And the event gets triggered properly *and* the item appears selected in the gallery - we're in business! This looks much better than a ComboEditorTool that simply lists the names of the various themes.
I was under the impression that setting SelectedItem would yield the same result (and it never occurred to me to try setting IsSelected instead - I guess I'm fighting on too many fronts this week. :))
Thanks a lot for your help!Michel
I tried this out and setting the IsSelected of the GalleryItem (e.g. this.gallery.Items[0].IsSelected = true;) did raise the ItemSelected event (assuming that its IsSelected wasn't already true). If you're not seeing the same behavior then its possible there was a fix in this area in which case I would recommend getting the latest hotfix - you may need to contact the support group.