Iva*_*čić 2 c# filepath windows-phone-8
我正在开发一个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>
Run Code Online (Sandbox Code Playgroud)
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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我现在希望通过点击图像,用户可以获得共享选项
void ShowShareMediaTask(object sender, GestureEventArgs e)
{
ShareMediaTask shareMediaTask = new ShareMediaTask();
shareMediaTask.FilePath = //something needs to go here
shareMediaTask.Show();
}
Run Code Online (Sandbox Code Playgroud)
我有什么想法可以获得这张图片的物理(完整)路径?
Oli*_*yen 13
看起来您正在引用存储在应用程序文件夹(在项目中)中的图像,因此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();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4073 次 |
| 最近记录: |