如何在新窗口中打开图像 [英] How do I open an image in a new window

查看:127
本文介绍了如何在新窗口中打开图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个可执行文件,其中包含一个包含数据模板的列表框。数据通过Linq2XML从XML文件中提取。



列表框中的数据是一个设置为200px宽的图像。我有代码在单击图像时打开一个新窗口并显示相同图像的更大版本。我的问题是让点击的图像在新窗口中打开。



我假设我必须将{Binding Path = Artwork}中的图像存储到某些图像中一种图像变量,但我不知道如何去做。

I am writing an executable that has a list box that contains a data template. The data is pulled from an XML file via Linq2XML.

Within the data in the list box is an image that is set to 200px wide. I have code to open a new window when when the image is clicked and show a larger version of the same image. My problem is getting the image that was clicked to open in the new window.

I assume I must have to store the image from {Binding Path=Artwork} into some sort of image variable, but I don't know how to go about it.

推荐答案

可能你正在使用 System.Windows.Controls。 Image ,它是 System.Windows.UIElement ,可以在XAML中使用:https://msdn.microsoft.com/en-us/library/system.windows.controls.image% 28v = vs.110%29.aspx



你需要的只是改变它的 ImageSource 在运行期间:

https://msdn.microsoft.com/en-us/library/system.windows.controls.image.source%28v=vs.110%29.aspx (请参阅此处的代码示例) ,

https://msdn.microsoft.com/en-us/library/system.windows.media .imagesource%28v = vs.110%29.aspx



粗略地说,真实图像是图像源的实例, Image 的实例只是 UIElement ,它会呈现一些图像。因此,它提供了额外的灵活性:您不需要从逻辑树中删除 Image 图像的实例(另请参阅< a href =https://msdn.microsoft.com/en-us/library/ms753391%28v=vs.110%29.aspx> https://msdn.microsoft.com/en-us/library/ms753391窗口的%28v = vs.110%29.aspx )并插入一个新实例;相反,你只需更改要渲染的图像 - 上面引用的属性是可读/写的。



-SA
Probably you are using System.Windows.Controls.Image, which is System.Windows.UIElement and can be used in XAML: https://msdn.microsoft.com/en-us/library/system.windows.controls.image%28v=vs.110%29.aspx.

All you need is to change its ImageSource during runtime:
https://msdn.microsoft.com/en-us/library/system.windows.controls.image.source%28v=vs.110%29.aspx (see the code sample here),
https://msdn.microsoft.com/en-us/library/system.windows.media.imagesource%28v=vs.110%29.aspx.

Roughly speaking, the "real image" is the instance of image source, and the instance of Image is just the UIElement which renders some image. Therefore, it gives your additional level of flexibility: you don't need to remove the instance of Image image from the logical tree (see also https://msdn.microsoft.com/en-us/library/ms753391%28v=vs.110%29.aspx) of your window and insert a new instance; instead, you just change the image to be rendered — the property referenced above is read/write.

—SA


这篇关于如何在新窗口中打开图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆