tags:

views:

694

answers:

1

Hi,

In my app I want to resize thumbinal Image when I click it, all images are in ItemTemplate where its Source property is bind to url to picture.

I try something like this (this is in my DataTemplate file)

<TextBlock>
   <Hyperlink TextDecorations="None"
               Command="helpers:StatusesCommands.ShowPicture"
               CommandParameter="{Binding}">
                    <Image Source="{Binding Path=FirstPictureUrl}" Margin="5"   />
   </Hyperlink>
</TextBlock>

But in Command handler I don't know how to get to this image. The OriginalSource propoerty on ExecutedRoutedEventArgs is set to HyperLink and Source is set to my control.

Maybe it's possible to set CommangParameter to my nested Image, but I don't know how to do it. Do you have any idea how to solve this?

+2  A: 

You are binding the command parameter to the data context, so you will have access to the image path in the command parameter, if you cast the parameter correctly.

To pass the image as the command parameter directly, first name the Image:

<Image x:Name="myImg" Source="{Binding Path=FirstPictureUrl}" Margin="5"/>

Bind the CommandParameter to this image:

CommandParameter="{Binding ElementName=myImg}"

It's not clear where you are handling this command. If you are handling it in code behind for this XAML, you could name the Image element and refer to it by name in the code behind file. However, it's usually better practice to pass what you need to the command as a parameter. Sometimes the command is handled far away from where the command is triggered.

Josh G
Thanks it works :)
ksirg