Exemple #1
0
        public void ChangeBackground(System.Drawing.Image img)
        {
            Application.Current.MainWindow.Width  = img.Width;
            Application.Current.MainWindow.Height = img.Height;
            StreamImage.Width  = img.Width;
            StreamImage.Height = img.Height;
            using (MemoryStream ms = new MemoryStream())
            {
                img.Save(ms, ImageFormat.Jpeg);
                ms.Position = 0;
                BitmapImage bmp = new BitmapImage();
                try
                {
                    bmp.BeginInit();
                    bmp.StreamSource = ms;
                    bmp.EndInit();
                    bmp.Freeze();

                    /*StreamImage.Source = bmp as ImageSource;
                     * if (!StreamImage.Source.IsFrozen && StreamImage.Source.CanFreeze)
                     *  StreamImage.Source.Freeze();
                     */
                    StreamImage.BeginInit();
                    StreamImage.Source = bmp as ImageSource;
                    StreamImage.EndInit();
                    //MessageBox.Show("a");
                }
                catch (Exception e) { }
            }
        }
        protected override DataTemplate SelectTemplateCore(object image)
        {
            if (image == null)
            {
                return(Default);
            }

            return(image switch
            {
                FileImage _ => File,
                StreamImage _ => Stream,
                TextImage _ => Text,
                ImageBase _ => Default,

                _ => throw new ArgumentException($"{nameof(image)} must inherit from {nameof(ImageBase)}."),
            });