private void providers_ProviderAvailabilityChanged(Object sender, ProviderEventArgs e) { try { if (this.Dispatcher.Thread != System.Threading.Thread.CurrentThread) { providers_ProviderAvailabilityChangedCallback bR = new providers_ProviderAvailabilityChangedCallback(providers_ProviderAvailabilityChanged); this.Dispatcher.Invoke(bR, new object[] { sender, e }); return; } // StackPanel newPanel = e.IsAvailable ? stackIcons : stackInactiveIcons; StackPanel oldPanel = e.IsAvailable ? stackInactiveIcons : stackIcons; // List<UIElement> itemListToRemove = new List<UIElement>(); // append to remove list foreach (System.Windows.Controls.Image currentBox in oldPanel.Children) { //log.Debug("old panel " + e.Name + " " + currentBox.Tag + " " + this.Dispatcher.Thread.ManagedThreadId); if (String.Compare(currentBox.Tag.ToString(), e.Name, true) == 0) { itemListToRemove.Add(currentBox); } } // append to remove list foreach (System.Windows.Controls.Image currentBox in newPanel.Children) { //log.Debug("old panel " + e.Name + " " + currentBox.Tag + " " + this.Dispatcher.Thread.ManagedThreadId); if (String.Compare(currentBox.Tag.ToString(), e.Name, true) == 0) { itemListToRemove.Add(currentBox); } } // remove ui elements from stackpanel foreach (UIElement uiElem in itemListToRemove) { oldPanel.Children.Remove(uiElem); newPanel.Children.Remove(uiElem); } // System.Drawing.Image img = e.Image; if (!e.IsAvailable) { img = this.getGrayscale(new Bitmap(img)); } // System.Windows.Controls.Image imgControl = new System.Windows.Controls.Image(); imgControl.Tag = e.Name; imgControl.Width = 15; imgControl.Height = 15; imgControl.Margin = new Thickness(0, 0, 10, 0); imgControl.Source = this.getBitmapSource(img); // newPanel.Children.Add(imgControl); // txtSearch.Focusable = newPanel.Children.Count > 0; if (txtSearch.Focusable) { txtSearch.Focus(); } txtSearch.Background = txtSearch.Focusable ? System.Windows.Media.Brushes.White : System.Windows.Media.Brushes.LightGray; } catch (Exception ex) { log.Error(ex, ex); } }
private void providers_ProviderAvailabilityChanged(Object sender, ProviderEventArgs e) { try { if (this.Dispatcher.Thread != System.Threading.Thread.CurrentThread) { providers_ProviderAvailabilityChangedCallback bR = new providers_ProviderAvailabilityChangedCallback(providers_ProviderAvailabilityChanged); this.Dispatcher.Invoke(bR, new object[] { sender, e }); return; } // StackPanel newPanel = e.IsAvailable ? stackIcons : stackInactiveIcons; StackPanel oldPanel = e.IsAvailable ? stackInactiveIcons : stackIcons; // List <UIElement> itemListToRemove = new List <UIElement>(); // append to remove list foreach (System.Windows.Controls.Image currentBox in oldPanel.Children) { //log.Debug("old panel " + e.Name + " " + currentBox.Tag + " " + this.Dispatcher.Thread.ManagedThreadId); if (String.Compare(currentBox.Tag.ToString(), e.Name, true) == 0) { itemListToRemove.Add(currentBox); } } // append to remove list foreach (System.Windows.Controls.Image currentBox in newPanel.Children) { //log.Debug("old panel " + e.Name + " " + currentBox.Tag + " " + this.Dispatcher.Thread.ManagedThreadId); if (String.Compare(currentBox.Tag.ToString(), e.Name, true) == 0) { itemListToRemove.Add(currentBox); } } // remove ui elements from stackpanel foreach (UIElement uiElem in itemListToRemove) { oldPanel.Children.Remove(uiElem); newPanel.Children.Remove(uiElem); } // System.Drawing.Image img = e.Image; if (!e.IsAvailable) { img = this.getGrayscale(new Bitmap(img)); } // System.Windows.Controls.Image imgControl = new System.Windows.Controls.Image(); imgControl.Tag = e.Name; imgControl.Width = 15; imgControl.Height = 15; imgControl.Margin = new Thickness(0, 0, 10, 0); imgControl.Source = this.getBitmapSource(img); // newPanel.Children.Add(imgControl); // txtSearch.Focusable = newPanel.Children.Count > 0; if (txtSearch.Focusable) { txtSearch.Focus(); } txtSearch.Background = txtSearch.Focusable ? System.Windows.Media.Brushes.White : System.Windows.Media.Brushes.LightGray; } catch (Exception ex) { log.Error(ex, ex); } }