Ejemplo n.º 1
0
        private void Import_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.DefaultExt = ".png";
            dlg.Filter     = "PNG files (.png)|*.png|All files|*";

            if (!(dlg.ShowDialog() ?? false))
            {
                return;
            }

            try
            {
                Bitmap image = TextureWorker.ReadImageFromFile(dlg.FileName);
                image.SetResolution(96.0F, 96.0F);
                (this.DataContext as UndertaleTexturePageItem).ReplaceTexture(image);

                // Refresh the image of "ItemDisplay"
                if (ItemDisplay.FindName("RenderAreaBorder") is not Border border)
                {
                    return;
                }
                if (border.Background is not ImageBrush brush)
                {
                    return;
                }
                BindingOperations.GetBindingExpression(brush, ImageBrush.ImageSourceProperty)?.UpdateTarget();
            }
            catch (Exception ex)
            {
                mainWindow.ShowError(ex.Message, "Failed to import image");
            }
        }