コード例 #1
0
        public void fillparts()
        {
            var parts = BP.GetUsedPartsList();

            if (parts != null)
            {
                if (!parts.Equals(this.parts) || true)
                {
                    new Thread(() =>
                    {
                        List <Part_listitem> part_Listitems = new List <Part_listitem>();
                        foreach (var uuid in parts.Keys)
                        {
                            part_Listitems.Add(new Part_listitem()
                            {
                                name = parts[uuid].Item1, amount = parts[uuid].Item3.ToString(), uuid = uuid
                            });
                        }
                        this.Dispatcher.Invoke((Action)(() =>
                        {
                            //listBox_parts.ItemsSource = null;
                            listBox_parts.ItemsSource = part_Listitems;
                        }));
                        ImageToBitmapSourceConverter converter = new ImageToBitmapSourceConverter();
                        foreach (Part_listitem item in part_Listitems)
                        {
                            var bmp = Database.blocks[item.uuid].GetIcon(item.uuid);
                            if (bmp != null)
                            {
                                item.icon         = (BitmapSource)converter.Convert(bmp.Clone(), null, typeof(BitmapSource), null);
                                item.emptysurface = 0;
                                item.iconheight   = 100;
                            }
                        }
                        this.Dispatcher.Invoke((Action)(() =>
                        {
                            listBox_parts.ItemsSource = null;
                            listBox_parts.ItemsSource = part_Listitems;
                        }));
                    }
                               ).Start();
                    this.parts = parts;
                }
            }
        }