Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Comments
Sergey Alexandrovich Kryukov 13-Apr-15 16:42pm    
Not clear what is the problem here. You are showing the XAML with fixed source, but how is it related to the case when you have to change the source on some event?
—SA

1 solution

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
 
Share this answer
 
v2
Comments
Sean Donnahoe 14-Apr-15 13:10pm    
I think you might have missed the point. There is an image (coming from data binding) in the main window that is when clicked, should open in a new xaml window. I need to know how to capture the source of the image that was clicked and have it passed to the new window.
Sergey Alexandrovich Kryukov 14-Apr-15 15:21pm    
The point can be different only if you explain what you want to achieve in terms of you ultimate goals, not in terms of your understanding of how it should be achieved. If you pull data from XML via Linq2XML, very good, this is runtime data... What is your concern here? Pull it and assign to the property as I suggested.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900