C# 在windows phone上删除gridview中的图像

C# 在windows phone上删除gridview中的图像,c#,image,gridview,windows-phone-8.1,C#,Image,Gridview,Windows Phone 8.1,我制作了一个包含图像的gridview。图像存储在windows phone 8.1的thumb文件夹中。我想从windows phone上的gridview和thumb文件夹中删除选定的图像 xaml: <GridView x:Name="itemGridView" AutomationProperties.AutomationId="ItemsGridView" AutomationProperties.Name="Items" TabIndex="1"

我制作了一个包含图像的gridview。图像存储在windows phone 8.1的thumb文件夹中。我想从windows phone上的gridview和thumb文件夹中删除选定的图像

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>

但在我按下“hapus”按钮后,图片并没有被删除,仍然在gridview中。请帮助我

我认为您应该从绑定到gridview的observablecollection中删除缩略图。您能给我一个示例吗?尝试将您的整个代码粘贴到您要在xaml中将列表或observablecollection绑定到itemGridView的位置
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();
}