Reputation: 1911
I am developing a Windows Phone 8 application and have some pictures already in it which are populated into a listbox like this
<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>
The ViewModel is simple at the momment
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);
}
}
}
I now want that by tapping on an image the user gets options for sharing
void ShowShareMediaTask(object sender, GestureEventArgs e)
{
ShareMediaTask shareMediaTask = new ShareMediaTask();
shareMediaTask.FilePath = //something needs to go here
shareMediaTask.Show();
}
Any ideas how I can get the physical (full) path of this image?
Upvotes: 2
Views: 4091
Reputation: 1435
yes... you can generate tap event of list box follow below code
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();
}
}
hope it will help you
Upvotes: 0
Reputation: 15268
It looks like you are referencing images stored in the application folder (in the project) so the ShareMediaTask
can't access it.
The ShareMediaTask
requires the photo to be in the Media Library.
What you need to do is save the photo the the Media Library and then call the ShareMediaTask
with the path of the saved image (don't forget to add the using Microsoft.Xna.Framework.Media.PhoneExtensions;
to have access to the GetPath()
extension method).
var picture = mediaLibrary.SavePicture(fileName, stream);
shareMediaTask = new ShareMediaTask();
shareMediaTask.FilePath = picture.GetPath(); // requires using Microsoft.Xna.Framework.Media.PhoneExtensions;
shareMediaTask.Show();
Upvotes: 13