Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
395
How to make Largest Item always selected
posted

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.

Parents
  • 395
    posted

    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;
            }

Reply Children