Hello I am using the XamCarouselPanel to host a number of buttons. Everything works great as long as I use the mouse but I would also like to add keyboard support. With they Keyboard I can make my contained buttons scroll and zoom in and out, but I want to add the concept of the largest item being the button that will be clicked if the user presses the enter button. So I would like to place a border ALWAYS around the largest item. Also I would like the enter key press to cause it to be clicked.
Should I be using the xamCarouselListBox for this? I tried it but I don't like how I can select items further in the background. I want the item in the forefront to always be selected only.
If you have any tips they would be appreciated.
Thanks.
In case anyone is interested FirstVisibleItemIndex changes as the user spins the carousel. I was able to get the CarouselPanelItem from the XamCarouselPanel1.ChildElements using this Index and a Fixed Offset. Works fine as long as the list is fixed.
Here is the code I used. Now If we had a TopZOrder Dependency Property we could use styles instead.
Button m_OldButton = null; Brush m_OldBrush = null;
//Changes Visuals On Top Z Order Button //And Restores Visuals On Last Top Z Order Button //*****************************HI_LITE_TOP_Z_ORDER************************* private void HiLiteTopZOrder() { if (m_OldButton != null) {//Restore the Button To Old Color m_OldButton.Background = m_OldBrush; }
System.Windows.Media.LinearGradientBrush lgbr = (System.Windows.Media.LinearGradientBrush)Grid_1.FindResource("LinearGradientBrush_1"); Button b = GetCurrentButton(); m_OldButton = b; m_OldBrush = b.Background; b.Background = lgbr; }
//If the Carousel Path is changed and/or items are added the 2 below may need to be changed. //********************************GET_CURRENT_INDEX*********************** private int GetCurrentIndex() { int findex = XamCarouselPanel1.FirstVisibleItemIndex + 2; if (findex >= XamCarouselPanel1.ChildElements.Count) findex -= XamCarouselPanel1.ChildElements.Count; return findex; } //*****************************GET_CURRENT_BUTTON************************ private Button GetCurrentButton() { CarouselPanelItem cpi = (CarouselPanelItem)XamCarouselPanel1.ChildElements[GetCurrentIndex()]; return (Button)cpi.Content; }
private void OnWindowInitialized(object sender, EventArgs e) { EventManager.RegisterClassHandler(typeof(MyWindow), UIElement.PreviewKeyDownEvent, new KeyEventHandler(OnPreviewKeyDown)); } private static void OnPreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e) { if (e.Key == Key.Enter) // Click the largest button }
private void OnWindowInitialized(object sender, EventArgs e)
{
EventManager.RegisterClassHandler(typeof(MyWindow), UIElement.PreviewKeyDownEvent, new KeyEventHandler(OnPreviewKeyDown));
}
private static void OnPreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
if (e.Key == Key.Enter)
// Click the largest button
Yeah that works. I got it working now thanks. Really the trickiest thing was determining what is the largest item or should I say what has the top Z-order. That would be a nice enhancement in the future to add a dependency property to the control that automatically gives me the top z-order item index. With a fixed list I can use a fixed offset from the FirstVisibleItemIndex, but if I modify my list at runtime, I don't think that would work.
Thanks for this. Yeah now you made me realize it always depends on the ItemsPerPage.
Here is what I am doing now
int Zindex = XamCarouselPanel1.FirstVisibleItemIndex + (XamCarouselPanel1.ItemsPerPageResolved / 2);
Zindex -= XamCarouselPanel1.ItemsPerPageResolved;
Works good.
-Greg.