private void AddConditionUserControl(SearchCriterias.UserControlType userControlType, List <ComboBoxItem> listComboBoxItem)
        {
            SearchCriterias searchCriterias = new SearchCriterias(userControlType, listComboBoxItem);

            searchCriterias.eventUserControlClose += new SearchCriterias.EventUserControlClose(searchCriterias_eventUserControlClose);
            if (scrollVSearchCriteria.ActualWidth > 10)
            {
                searchCriterias.Width = scrollVSearchCriteria.ActualWidth - 10;
            }
            _searchCriteria.Add(searchCriterias);
            if (_searchCriteria.Count == 2)
            {
                UIElement _uiElement = _searchCriteria[0].grdMain.Children.Cast <UIElement>().Where(x => x.Visibility == System.Windows.Visibility.Visible).FirstOrDefault();
                if (_uiElement is Grid)
                {
                    Grid tempGrid   = _uiElement as Grid;
                    var  tempButton = tempGrid.Children.OfType <Button>().Where(x => x.GetType() == typeof(Button));
                    foreach (Button tempbtn in tempButton)
                    {
                        tempbtn.Visibility = System.Windows.Visibility.Visible;
                    }
                }
            }
            itcSearchCriteria.ItemsSource = _searchCriteria;
        }
 private void searchCriterias_eventUserControlClose(SearchCriterias instance)
 {
     if (_searchCriteria.Count > 1)
     {
         instance.eventUserControlClose -= searchCriterias_eventUserControlClose;
         _searchCriteria.Remove(instance);
         if (_searchCriteria.Count == 1)
         {
             UIElement _uiElement = _searchCriteria[0].grdMain.Children.Cast <UIElement>().Where(x => x.Visibility == System.Windows.Visibility.Visible).FirstOrDefault();
             if (_uiElement is Grid)
             {
                 Grid tempGrid   = _uiElement as Grid;
                 var  tempButton = tempGrid.Children.OfType <Button>().Where(x => x.GetType() == typeof(Button));
                 foreach (Button tempbtn in tempButton)
                 {
                     tempbtn.Visibility = System.Windows.Visibility.Collapsed;
                 }
             }
         }
         instance = null;
     }
     else
     {
         instance.ResetUI();
     }
     itcSearchCriteria.ItemsSource = _searchCriteria;
 }