Delete image file used by XAML
        Posted  
        
            by Frode Lillerud
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Frode Lillerud
        
        
        
        Published on 2010-04-02T08:42:16Z
        Indexed on 
            2010/04/02
            8:53 UTC
        
        
        Read the original article
        Hit count: 424
        
I'm trying to delete a Image file in WPF, but WPF locks the file.
    <Image Source="C:\person.gif" x:Name="PersonImage">
        <Image.ContextMenu>
            <ContextMenu>
                <MenuItem Header="Delete..." x:Name="DeletePersonImageMenuItem" Click="DeletePersonImageMenuItem_Click"/>
            </ContextMenu>
        </Image.ContextMenu>
    </Image>
And the Click handler just looks like this:
    private void DeletePersonImageMenuItem_Click(object sender, RoutedEventArgs e)
    {
        System.IO.File.Delete(@"C:\person.gif");
    }
But, when I try to delete the file it is locked and cannot be removed.
Any tips on how to delete the file?
© Stack Overflow or respective owner