c# - 在Windows Phone上获取图像的文件路径

标签 c# windows-phone-8 filepath

我正在开发一个 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/

相关文章:

c# - 检查 HtmlString 在 C# 中是否为空格

c# - 将类型转换为 IDisposable - 为什么?

c# - DLL 重定向 - 内部版本号不匹配

javascript - 如何在 windows phonegap 应用程序中加载页面后动态更改元标记视口(viewport)?

c# - Powershell Cmdlet : Determine actual filepath of file in local directory

c# - 如何在 OFB 模式下使用 C# 中的 3DES 解密?

windows-phone-8 - WinRT FlipView 类似 WP8 中的控件

authentication - 在 Azure 移动服务中注册和登录用户

javascript - 如何在路径中插入变量

c# - 如何获取类库的当前目录?