繁体   English   中英

如何获取GestureCompleted上图像的来源

[英]How do I get the Source of an Image on GestureCompleted

我想在拖动图像时在手机屏幕上找到图像的URI。 屏幕上有很多图像,我需要知道拖动了哪一个图像,我可以从图像的文件名中轻松找到它们,因为它们的名称分别为A.png, B.png and so on

    private void OnGestureCompleted(object sender, Microsoft.Phone.Controls.GestureEventArgs e){
        Image image = sender as Image;
        TranslateTransform transform = image.RenderTransform as TranslateTransform;
        //storing the final values after the gesture is complete
        xFin = (e.GetPosition(null).X);
        yFin = (e.GetPosition(null).Y);
        //failed attempts to convert adress to string
        MessageBox.Show(image.Source.ToString());
    }

这将返回System.Windows.Controls.Image 另一方面,这引发了一个异常,指出尚未实现ConvertToString。

ImageSourceConverter convertor = new ImageSourceConverter();
string location = convertor.ConvertToString(image);
MessageBox.Show(location);

有什么办法可以做到吗?

如果您知道Source属性是BitmapImage (如果您正在将URI传递给XAML中Source属性中的Image的话),则可以使用UriSource:

MessageBox.Show(((BitmapImage)image.Source).UriSource.ToString());

我建议您使用Image控件的Tag属性来存储所需的信息。 从长远来看,可扩展性更强。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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