简体   繁体   中英

How to get object from sender parameter in C# in Windows-Phone-7

I want to get source of my image control by clicking the image in my wp7 application I try this one but not get solution.

Image img = new Image();
img.Source = new BitmapImage(uri);
img.Height = 105;
img.Width = 167;
img.Margin = new Thickness(Xpos, Ypos, 0, 0);
//img.Height = j;
img.MouseLeftButtonUp += new MouseButtonEventHandler(img_MouseLeftButtonUp);

void img_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
     var image = (Image)sender;
     MessageBox.Show(image.Source.ToString());
}

Please give me some idea how can i get source of my image control. Thanks in advance

您将需要将Image.Source转换为System.Windows.Media.Imaging.BitmapImage以获得UriSource

MessageBox.Show(((System.Windows.Media.Imaging.BitmapImage)image.Source).UriSource.ToString());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM