I made a gridview that contains the images. Images are stored in a thumb folder in windows phone 8.1. I want to delete a selected image from gridview and thumb folder on my windows phone
The xaml:
<GridView
x:Name="itemGridView"
AutomationProperties.AutomationId="ItemsGridView"
AutomationProperties.Name="Items"
TabIndex="1"
IsSwipeEnabled="false"
Padding="50,30,0,0"
HorizontalAlignment="Left"
Foreground="{x:Null}" RightTapped="itemGridView_RightTapped" SelectedItem="None">
<GridView.ItemTemplate>
<DataTemplate>
<Grid Height="400" Width="285" Margin="20,20,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image Source="{Binding Image}" AutomationProperties.Name="{Binding Name}" x:Name="myImage" Stretch="Uniform"/>
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
The code:
private async void itemGridView_RightTapped(object sender, RightTappedRoutedEventArgs e)
{
StorageFolder thumbfolder = await installedLocation.CreateFolderAsync("thumb", CreationCollisionOption.OpenIfExists);
Book hapusbuku = this.itemGridView.SelectedItem as Book;
MessageDialog messageDialog;
String deskripsi = String.Format("Yakin menghapus buku {0}?", hapusbuku.Name);
messageDialog = new MessageDialog(deskripsi, "Hapus Buku");
// Add commands and set their callbacks
messageDialog.Commands.Add(new UICommand("Batal", (command) =>
{
//rootPage.NotifyUser("The 'Don't install' command has been selected.", NotifyType.StatusMessage);
}));
messageDialog.Commands.Add(new UICommand("Hapus", async (command) =>
{
try
{
thumbfolder.GetFileAsync(hapusbuku.Name + ".png");
await thumb.DeleteAsync();
this.itemGridView.SelectedItem = itemGridView.Items[0];
}
catch
{
this.itemGridView.SelectedItem = itemGridView.Items[0];
}
}));
// Show the message dialog
await messageDialog.ShowAsync();
}
but after I press the "hapus" button, the picture is not deleted and still in the gridview. Please help me
Aucun commentaire:
Enregistrer un commentaire