[英]Get filepath of image on windows phone
我正在開發一個Windows Phone 8應用程序,並且已經有一些圖片已經填充到這樣的列表框中
<ListBox x:Name="Control" ItemsSource="{Binding Pictures}">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Background="WhiteSmoke" Margin="10">
<Image Source="{Binding Source}" Margin="10"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
ViewModel很簡單
public class MainPageViewModel : NotificationObject
{
private ObservableCollection<Picture> _pictures;
public MainPageViewModel()
{
Pictures = new ObservableCollection<Picture>
{
new Picture
{
Source = new BitmapImage(new Uri("../Images/Pictures/1.jpg", UriKind.Relative))
}
//Add more images here
};
}
public ObservableCollection<Picture> Pictures
{
get { return _pictures; }
set
{
_pictures = value;
RaisePropertyChanged(() => Pictures);
}
}
}
我現在希望通過點擊圖像,用戶可以獲得共享選項
void ShowShareMediaTask(object sender, GestureEventArgs e)
{
ShareMediaTask shareMediaTask = new ShareMediaTask();
shareMediaTask.FilePath = //something needs to go here
shareMediaTask.Show();
}
我有什么想法可以獲得這張圖片的物理(完整)路徑?
看起來您正在引用存儲在應用程序文件夾(在項目中)中的圖像,因此ShareMediaTask
無法訪問它。
ShareMediaTask
要求照片在媒體庫中。
您需要做的是將照片保存在媒體庫中,然后使用保存圖像的路徑調用ShareMediaTask
(不要忘記using Microsoft.Xna.Framework.Media.PhoneExtensions;
添加using Microsoft.Xna.Framework.Media.PhoneExtensions;
以訪問GetPath()
擴展方法)。
var picture = mediaLibrary.SavePicture(fileName, stream);
shareMediaTask = new ShareMediaTask();
shareMediaTask.FilePath = picture.GetPath(); // requires using Microsoft.Xna.Framework.Media.PhoneExtensions;
shareMediaTask.Show();
是的...您可以按照以下代碼生成列表框的點擊事件
private void Control_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
ObservableCollection<Picture> pictureobj=new ObservableCollection<Picture>();
ListBox lst = (ListBox)sender;
int i = lst.SelectedIndex;
if (lst.SelectedValue == null)
{
}
else
{
Pictures obj = (Pictures)lst.SelectedValue;
ShareMediaTask shareMediaTask = new ShareMediaTask();
shareMediaTask.FilePath = obj.yoursetterimagepath
shareMediaTask.Show();
}
}
希望它會對你有所幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.