public void FillForm()
        {
            //Fill combo with linked documents
            foreach (var item in Clash.Documents(RevitTools.Doc, RevitTools.App))
            {
                ListOfLinks.Items.Add(item.Key);
            }
            var SelectionA = new List <CheckBox>();
            var SelectionB = new List <CheckBox>();
            var categories = FormTools.ListOfCategories(RevitTools.Doc);

            foreach (var c in categories)
            {
                //List of
                CheckBox chbox = new CheckBox();
                chbox.Content = c.Key;
                SelectionB.Add(chbox);
                //   SelectionAList.Items.Add(chbox);
            }

            foreach (var c in categories)
            {
                //List of
                CheckBox chbox = new CheckBox();
                chbox.Content = c.Key;
                SelectionA.Add(chbox);
                //   SelectionAList.Items.Add(chbox);
            }
            SelectionAList.ItemsSource = SelectionA;
            SelectionBList.ItemsSource = SelectionB;

            //Presetting everything from a previous run
            foreach (var item in Clasher.Properties.Settings.Default.SelectionB)
            {
                int      i     = int.Parse(item);
                CheckBox chbox = SelectionBList.Items[i] as CheckBox;
                chbox.IsChecked = true;
            }
            foreach (var item in Clasher.Properties.Settings.Default.SelectionA)
            {
                int      i     = int.Parse(item);
                CheckBox chbox = SelectionAList.Items[i] as CheckBox;
                chbox.IsChecked = true;
            }
            ListOfLinks.SelectedIndex = Properties.Settings.Default.ListOfLinks;
        }
        private void Run_Click(object sender, RoutedEventArgs e)
        {
            this.Results.Items.Clear();
            SaveConfiguration();
            RevitTools.CropBox = RevitTools.GetCropBox();
            StringCollection selectionACollection = Properties.Settings.Default.SelectionA;
            StringCollection selectionBCollection = Properties.Settings.Default.SelectionB;
            string           validationMessage    = string.Empty;
            bool             validationFlag       = false;


            // Validation of elements selected
            if (selectionACollection.Count == 0 || selectionBCollection.Count == 0)
            {
                validationFlag    = true;
                validationMessage = "Both categories must have elements selected to check for clashes";
            }

            if (ListOfLinks.SelectedItem == null)
            {
                validationFlag    = true;
                validationMessage = "Select a document to do the clash detection";
            }

            // If validationFlag is true. The validation dialog is showed.
            if (validationFlag)
            {
                TaskDialog.Show("Clash Detection", validationMessage, TaskDialogCommonButtons.Ok);
                return;
            }

            _Reset = false;
            //Save Selection
            SaveConfiguration();
            _wasExecuted = false;
            var index = Properties.Settings.Default.ListOfLinks;
            var l     = Clash.Documents(RevitTools.Doc, RevitTools.App);

            // Get document from select index
            FormTools.linkedDocument         = l.Values[index];
            FormTools.SelectedCategories     = new List <ElementFilter>();
            FormTools.SelectedHostCategories = new List <ElementFilter>();

            //Categories
            var cat = FormTools.ListOfCategories(RevitTools.Doc);


            //Get categories from select index
            foreach (var i in Properties.Settings.Default.SelectionB)
            {
                int             item      = int.Parse(i);
                BuiltInCategory myCatEnum = (BuiltInCategory)Enum.Parse(typeof(BuiltInCategory), cat.Values[item].Id.ToString());
                FormTools.SelectedCategories.Add(new ElementCategoryFilter(myCatEnum));
            }

            //Get categories from select index
            foreach (var i in Properties.Settings.Default.SelectionA)
            {
                int             item      = int.Parse(i);
                BuiltInCategory myCatEnum = (BuiltInCategory)Enum.Parse(typeof(BuiltInCategory), cat.Values[item].Id.ToString());
                FormTools.SelectedHostCategories.Add(new ElementCategoryFilter(myCatEnum));
                //Saving the local categories for a new run
            }
            m_ExEvent.Raise();
        }