簡體   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