I am using CarouselPanel.ExecuteCommand(XamCarouselPanelCommands.NavigateToNextItem) in a timer to automatically move to the next item. How can I get a hold of the current item as I need to perform other actions on the screen when certain items are "selected". I have looked at the ExecutingCommand/ExecutedCommand events, but can't seem to find a way to know what is "selected".
Thanks for your help.
Mike
Hello Mike,
You have to select the items manually when the carousel panel is rotating. To do that,
you can handle the ExecutedCommand event and check which command is executed :
if(e.Command == XamCarouselPanelCommands.NavigateToNextItem)
{
//custom logic.
}
Hope this helps.
I tried that, but how do I get the current panel inside this event? I'm building my panels dynamically and need to get the panel when it is "selected".
This is how I add my child elements where BuildPanel returns a StackPanel.
For Each group In dasboard.Elements("group") CarouselPanel.ChildElements.Add(BuildPanel(group))Next
Actually, I might have mislead you. I am not completely sure, but the XamCarouselPanel does not provide selection support. It is just used to put elements inside it. The XamCarouselListBox adds selection support, and the XamDataCarousel is used to display tabular data. You might want to consider using the XamCarouselListBox if you want to control selection.
I might have misled you by by word "selected". I don't want selection support, I just need to know which panel is currently in the foreground. Internally you have to know which panel is currently in front. How can I get that information? If I have 15 panels in the collection and have it showing 3 at a time, I need to know which of the 3 items is in front.
I have based my layout on your Custom CarouselPanelNavigator Style example (ItemNavigatorStyling_Samp.xaml). So in this example, lets say I want to pop up a message box displaying the source of the image in front as I rotate the carousel.
Thanks.
Oh,ok.
So, if you have three items at a time, you can use the HorizontalOffset property. The value will correspond to the number of items. For example, if you have three at a page, and you want the one in the middle (currently in the foreground) you can use this:
void xamCarouselPanel1_ExecutedCommand(object sender, Infragistics.Windows.Controls.Events.ExecutedCommandEventArgs e)
if (e.Command == XamCarouselPanelCommands.NavigateToNextItem || e.Command == XamCarouselPanelCommands.NavigateToPreviousItem)
Debug.WriteLine((xamCarouselPanel1.HorizontalOffset+2d).ToString());