Exemplo n.º 1
0
        public void ShouldConvertToBitmapSource()
        {
            ImageToBitmapSourceConverter converter = new ImageToBitmapSourceConverter();

            Assembly assembly    = Assembly.GetExecutingAssembly();
            Stream   imageStream = assembly.GetManifestResourceStream("Infrastructure.Tests.Resources.Treebark.png");

            object       value          = Image.FromStream(imageStream);
            BitmapSource convertedValue = converter.Convert(value, typeof(bool), null, null) as BitmapSource;

            Assert.IsNotNull(convertedValue);

            value          = null;
            convertedValue = converter.Convert(value, typeof(bool), null, null) as BitmapSource;
            Assert.IsNull(convertedValue);
        }
Exemplo n.º 2
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;
                }
            }
        }