我正在开发一个 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;
以访问 GetPath()
扩展方法。
var picture = mediaLibrary.SavePicture(fileName, stream);
shareMediaTask = new ShareMediaTask();
shareMediaTask.FilePath = picture.GetPath(); // requires using Microsoft.Xna.Framework.Media.PhoneExtensions;
shareMediaTask.Show();
关于c# - 在Windows Phone上获取图像的文件路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18654978/