如何使用按钮通过按钮点击事件将同一页面中的图像发送到应用程序中的另一个页面?
答案 0 :(得分:0)
在单击按钮时调用的方法中,我将使用应用程序属性来存储图像。这样的事情(你会想在你的图像上放一个数据类型):
Application.Current.Properties.Add("myImage", System.Windows.Media.Imaging.BitmapImage myBmp);
Window newWindow = new Window();
newWindow.Show();
然后在打开的窗口中,从这样的应用程序属性中抓取图像(请注意,您要将图像转换为所需的图像类型):
transferredImage = (MYIMAGETYPE)Application.Current.Properties["myImage"];
var brush = new ImageBrush();
if (image != null)
{
brush.ImageSource = image;
btnCustomerPhoto.Background = brush;
}
Application.Current.Properties.Clear();
当然,如果你不想要,你不必清除当前的属性,但是我确实没有任何东西可以让我不想要。
还有其他方法可以做到这一点,但应用程序属性易于使用,然后摆脱。