/// <summary>
        /// Add item to list box
        /// </summary>
        /// <param name="listBox">The listbox</param>
        /// <param name="text">Text string</param>
        /// <param name="tag">Tag object</param>
        /// <param name="waitUntilReturn">Wait until return</param>
        public static void AddItem(this ListBox listBox, string text, object tag, bool waitUntilReturn = false)
        {
            Action additem = () =>
            {
                var listBoxItem = new ListBoxItem();
                listBoxItem.Content = text;
                listBoxItem.Tag     = tag;

                ////lbit.Tag = index;
                listBox.Items.Add(listBoxItem);
            };

            if (listBox.CheckAccess())
            {
                additem();
            }
            else if (waitUntilReturn)
            {
                listBox.Dispatcher.Invoke(additem);
            }
            else
            {
                listBox.Dispatcher.BeginInvoke(additem);
            }
        }
Exemple #2
0
        public static void RemoveItem(this ListBox lb, bool waitUntilReturn = false)
        {
            Action additem = () => lb.Items.Remove("");

            if (lb.CheckAccess())
            {
                additem();
            }
            else if (waitUntilReturn)
            {
                lb.Dispatcher.Invoke(additem);
            }
            else
            {
                lb.Dispatcher.BeginInvoke(additem);
            }
        }
        /// <summary>
        /// Remove item
        /// </summary>
        /// <param name="listBox">The listbox</param>
        /// <param name="text">Text string</param>
        /// <param name="index">Int index</param>
        /// <param name="waitUntilReturn">Wait until return</param>
        public static void RemoveItem(this ListBox listBox, string text, int index, bool waitUntilReturn = false)
        {
            ////ListBoxItem lbit;
            ////lbit.Content = text;
            ////lbit.Tag = index;
            Action additem = () => listBox.Items.Remove(string.Empty);

            if (listBox.CheckAccess())
            {
                additem();
            }
            else if (waitUntilReturn)
            {
                listBox.Dispatcher.Invoke(additem);
            }
            else
            {
                listBox.Dispatcher.BeginInvoke(additem);
            }
        }
        /// <summary>
        /// Set item source
        /// </summary>
        /// <param name="listBox">The listbox</param>
        /// <param name="temp">Temp list</param>
        /// <param name="waitUntilReturn">Wait until return</param>
        public static void SetItemSource(this ListBox listBox, List <string> temp, bool waitUntilReturn = false)
        {
            Action additem = () =>
            {
                ////lbit.Tag = index;
                listBox.ItemsSource = temp;
            };

            if (listBox.CheckAccess())
            {
                additem();
            }
            else if (waitUntilReturn)
            {
                listBox.Dispatcher.Invoke(additem);
            }
            else
            {
                listBox.Dispatcher.BeginInvoke(additem);
            }
        }
Exemple #5
0
        public static void AddItem(this ListBox lb, string text, int index, bool waitUntilReturn = false)
        {
            var lbit = new ListBoxItem
            {
                Content = text,
                Tag     = index
            };
            Action additem = () => lb.Items.Add(lbit);

            if (lb.CheckAccess())
            {
                additem();
            }
            else if (waitUntilReturn)
            {
                lb.Dispatcher.Invoke(additem);
            }
            else
            {
                lb.Dispatcher.BeginInvoke(additem);
            }
        }
Exemple #6
0
 void AddToWindow(string s)
 {
     if (_lb.CheckAccess() == false)
     {
         _lb.Dispatcher.Invoke(
             System.Windows.Threading.DispatcherPriority.Normal,
             new Action(() =>
         {
             if (_lb.Items.Count > 3000)
             {
                 _lb.Items.RemoveAt(0);
             }
             _lb.Items.Add(s);
         }));
     }
     else
     {
         if (_lb.Items.Count > 3000)
         {
             _lb.Items.RemoveAt(0);
         }
         _lb.Items.Add(s);
     }
 }