在Windows Phone上删除gridview中的图像

时间:2015-04-16 08:57:43

标签: c# image gridview windows-phone-8.1

我制作了一个包含图像的gridview。图像存储在Windows Phone 8.1的拇指文件夹中。我想从我的Windows手机上的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>

代码:

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();
}

但在我按下&#34; hapus&#34;按钮,图片不会被删除,仍然在gridview中。请帮帮我

0 个答案:

没有答案