WPF 图像工具提示锁定文件



我有一个显示图像的列表框,该列表为用户提供了使用默认图像编辑器打开文件的选项。在列表中,图像有一个工具提示,其中显示图像的较大版本。

我的问题是,当显示工具提示时,图像被锁定,如果用户尝试编辑图像,则当他尝试保存时,他将获得访问共享冲突。

xaml 非常简单

<Image x:Name="_thumbImage" Source="{Binding Path}" >                  
                            <Image.ToolTip>
                                <Grid>
                                    <Image Source="{Binding Path,BindsDirectlyToSource=True,IsAsync=False}" Stretch="Fill" HorizontalAlignment="Center" Height="300" Width="300"></Image>
                                </Grid>
                            </Image.ToolTip>
                        </Image>

有人知道如何解决这个问题吗?

您可以显式创建一个BitmapImage,该将图像缓存在内存中并释放文件。请注意,没有必要加载图像两次,因此我将其放在资源中。

<Grid>
  <Grid.Resources> 
     <BitmapImage x:Key="Source" UriSource="{Binding Path}" />
  </Grid.Resources>                    
  <Image x:Name="_thumbImage" Source="{StaticResource Source}">
    <Image.ToolTip>
      <Grid>
        <Image Source="{StaticResource Source}" Stretch="Fill" 
                HorizontalAlignment="Center" 
                Height="300" Width="300">
        </Image>
      </Grid>
    </Image.ToolTip>
  </Image>
</Grid> 

最新更新