현재 WPF 대화 상자에 이미지를 표시하려고합니다.이 이미지는 언제든지 사용자가 바꿀 수 있으므로이 이미지 파일을 덮어 씁니다. 내 문제는 : 이미지가 내 대화 상자에 표시되는 동안 이미지가 WPF에 의해 잠긴 것처럼 보이므로이를 바꿀 때 액세스 할 수 없습니다.WPF에서 이미지 파일에 데이터 바인딩하면 해당 파일이 영구적으로 잠 깁니다.
새 이미지를 업로드 할 때 WPF에서 이미지를 강제로 해제하려면 어떻게해야합니까? 여기 내 코드의 일부입니다
XAML :
<Image Margin="6" VerticalAlignment="Center" HorizontalAlignment="Center" Source="{Binding ImageFileFullPath}"/>
C 번호 :
string sourceFile = openFileDialog.FileName;
string destinationFile = Path.Combine(Environment.ExpandEnvironmentVariables(Constants.ImagePathConstant), destinationFileWithoutPath);
mViewModel.ImageFileFullPath = ""; //temporarily set the image file to another entry hoping WPF releases my image
try
{
File.Copy(sourceFile, destinationFile, true); //fails the second time with exception
}
catch (Exception)
{
throw;
}
심지어 일시적으로 문제가 해결되지 않는 빈 경로에 이미지를 설정하려고합니다.
예외 내가 얻을 형식 'System.IO.IOException'처리되지 않은 예외가 나는 위치를 이동 한 후 표시하기 위해 나는 이미지를 선택하는 사용자가 필요한 상황이 있었다 PresentationFramework.dll
검사에 http : // 유래. co.kr/questions/1688545/problems-overwriting-re-saving-image-when-set-as-image-source –