Esempio n. 1
0
        public static void SelectListBoxItemByHisInnerControl(FrameworkElement sourceControl, ListBox targetListBox)
        {
            FrameworkElement lbItemContainer = AppLib.FindVisualParentByType((FrameworkElement)sourceControl, typeof(ListBoxItem));

            if (lbItemContainer == null)
            {
                return;
            }
            int idxContainer = targetListBox.ItemContainerGenerator.IndexFromContainer(lbItemContainer);

            if (idxContainer != targetListBox.SelectedIndex)
            {
                targetListBox.SelectedIndex = idxContainer;
            }
        }