Blacker.MangaScraper.Helpers.ListBoxExtension.ResynchList C# (CSharp) Méthode

ResynchList() private static méthode

private static ResynchList ( System.Windows.Controls.ListBox listBox ) : void
listBox System.Windows.Controls.ListBox
Résultat void
        private static void ResynchList(ListBox listBox)
        {
            if (listBox != null)
            {
                listBox.SetValue(IsResynchingPropertyKey, true);

                IList list = GetSelectedItemsSource(listBox);
                if (listBox.SelectionMode == SelectionMode.Single)
                {
                    listBox.SelectedItem = null; if (list != null)
                    {
                        if (list.Count > 1)
                        {
                            // There is more than one item selected, but the listbox is in Single selection mode
                            throw new InvalidOperationException("ListBox is in Single selection mode, but was given more than one selected value.");
                        }
                        if (list.Count == 1)
                            listBox.SelectedItem = list[0];
                    }
                }
                else
                {
                    listBox.SelectedItems.Clear();
                    if (list != null)
                    {
                        foreach (object obj in listBox.Items)
                        {
                            if (list.Contains(obj))
                                listBox.SelectedItems.Add(obj);
                        }
                    }
                }
                listBox.SetValue(IsResynchingPropertyKey, false);
            }
        }