图像已保存并显示在Win文件资源管理器中,不会在应用程序或VS中加载

几天以来我一直坚持这个问题,随着截止日期的临近,我真的在我的智慧结束。

我可以选择在我的应用程序中添加新客户。 客户存储在DB中,其ID,名称和徽标。 徽标只是图像文件名的字符串(如logo.png)
添加客户时,我从本地文件中选择一个图像作为客户的徽标添加。 它在Add-window中很好地显示出来。
确认新的Cutomer后,关闭CustomerAddView窗口。 客户是在数据库中创建的,数据库中的徽标值很好,在我的Windows文件资源管理器中,我看到它已添加。
将刷新主窗口中的Customers列表(CustomerListView)。 另一个客户的徽标工作正常。 但新客户的徽标会发出警告(如下所示)。

在Visual Studio中,即使我刷新并重建,新徽标仍然不起作用,并且它不会显示在解决方案资源管理器中。 这就像Visual Studio不承认图像的存在,因为它不是通过VS本身添加的。

我想知道为什么我的徽标图像在文件资源管理器中,在指定的文件夹中,但不会显示在客户列表中。
我想知道为什么图像在通过Visual Studio的解决方案资源管理器添加时可以正常工作,但是当我通过CustomerAddView(模型)添加它们(到同一文件夹)时不起作用。

屏幕截图显示文件夹结构,并显示通过VS添加的文件正在工作,而新的文件不是。 问题 我通过CustomerAddView(Model)添加了testlogo.png,另外3个是在VS Solution Explorer中添加的。 如你看到的:

  • 徽标都在同一目录中。
  • 只有通过VS Solution Explorer添加的徽标才会显示在VS Solution Explorer中。 新的没有。
  • 新徽标未显示在CustomerListView中。 其他人呢。

警告:

System.Windows.Data Warning: 6 : 'DynamicValueConverter' converter failed to convert value '../../Media/Images/Logos/testlogo.png' (type 'String'); fallback value will be used, if available. BindingExpression:Path=Logo; DataItem='Customer_5A59789E69DE0B010CE32D4E23A696EDB09551158A85050E8CA80E51475D369B' (HashCode=45868004); target element is 'Image' (Name=''); target property is 'Source' (type 'ImageSource') IOException:'System.IO.IOException: Kan bron media/images/logos/testlogo.png niet vinden. bij MS.Internal.AppModel.ResourcePart.GetStreamCore(FileMode mode, FileAccess access) bij System.IO.Packaging.PackagePart.GetStream(FileMode mode, FileAccess access) bij System.IO.Packaging.PackWebResponse.CachedResponse.GetResponseStream() bij System.IO.Packaging.PackWebResponse.GetResponseStream() bij System.IO.Packaging.PackWebResponse.get_ContentType() bij System.Windows.Media.Imaging.BitmapDecoder.SetupDecoderFromUriOrStream(Uri uri, Stream stream, BitmapCacheOption cacheOption, Guid& clsId, Boolean& isOriginalWritable, Stream& uriStream, UnmanagedMemoryStream& unmanagedMemoryStream, SafeFileHandle& safeFilehandle) bij System.Windows.Media.Imaging.BitmapDecoder.CreateFromUriOrStream(Uri baseUri, Uri uri, Stream stream, BitmapCreateOptions createOptions, BitmapCacheOption cacheOption, RequestCachePolicy uriCachePolicy, Boolean insertInDecoderCache) bij System.Windows.Media.Imaging.BitmapFrame.CreateFromUriOrStream(Uri baseUri, Uri uri, Stream stream, BitmapCreateOptions createOptions, BitmapCacheOption cacheOption, RequestCachePolicy uriCachePolicy) bij System.Windows.Media.ImageSourceConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value) bij MS.Internal.Data.DefaultValueConverter.ConvertHelper(Object o, Type destinationType, DependencyObject targetElement, CultureInfo culture, Boolean isForward) bij MS.Internal.Data.TargetDefaultValueConverter.Convert(Object o, Type type, Object parameter, CultureInfo culture) bij MS.Internal.Data.DynamicValueConverter.Convert(Object value, Type targetType, Object parameter, CultureInfo culture) bij System.Windows.Data.BindingExpression.ConvertHelper(IValueConverter converter, Object value, Type targetType, Object parameter, CultureInfo culture)' System.Windows.Data Error: 11 : Fallback value 'Default' (type 'String') cannot be converted for use in 'Source' (type 'ImageSource'). BindingExpression:Path=Logo; DataItem='Customer_5A59789E69DE0B010CE32D4E23A696EDB09551158A85050E8CA80E51475D369B' (HashCode=45868004); target element is 'Image' (Name=''); target property is 'Source' (type 'ImageSource') NullReferenceException:'System.NullReferenceException: De objectverwijzing is niet op een exemplaar van een object ingesteld. bij System.Windows.Media.ImageSourceConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value) bij System.Windows.Data.BindingExpressionBase.ConvertValue(Object value, DependencyProperty dp, Exception& e)' 

Thi是XAML代码,用于在列表中显示Customers及其徽标:

CustomerListView

                     Customer:            

这些是添加屏幕及其ViewModel:CustomerAddView:

              Customer name: *  Customer logo:    

CustomerAddViewModel:

 class CustomerAddViewModel : INotifyPropertyChanged { private RelayCommand addConfirmCommand; private RelayCommand selectLogoCommand; Image customerLogo; string logoDirectory = "../../Media/Images/Logos/"; DBCustomer dbCustomer = new DBCustomer(); #region Add Customer public ICommand AddConfirmCommand { get { return addConfirmCommand ?? (addConfirmCommand = new RelayCommand(() => AddConfirmCustomer())); } } private void AddConfirmCustomer() { if(newCustomer.Logo != null) { customerLogo.Save(logoDirectory + newCustomer.Logo); } else { newCustomer.Logo = "Default.png"; } if (!dbCustomer.Create(newCustomer)) { return; } App.Messenger.NotifyColleagues("AddCustomerDone"); } #endregion #region Add logo public ICommand SelectLogoCommand { get { return selectLogoCommand ?? (selectLogoCommand = new RelayCommand(() => SelectLogo())); } } private void SelectLogo() { OpenFileDialog chooseFile = new OpenFileDialog(); chooseFile.Title = "Select a logo"; chooseFile.Filter = "All supported graphics|*.jpg;*.jpeg;*.png|" + "JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" + "Portable Network Graphic (*.png)|*.png"; if(chooseFile.ShowDialog() == DialogResult.OK) { Stream reader = File.OpenRead(chooseFile.FileName); customerLogo = System.Drawing.Image.FromStream((Stream)reader); MemoryStream finalStream = new MemoryStream(); customerLogo.Save(finalStream, ImageFormat.Png); // translate to image source PngBitmapDecoder decoder = new PngBitmapDecoder(finalStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); NewCustomerLogo = decoder.Frames[0]; newCustomer.Logo = newCustomer.Name + ".png"; } } private ImageSource newCustomerLogo; public ImageSource NewCustomerLogo { get { return newCustomerLogo; } set { newCustomerLogo = value; OnPropertyChanged(new PropertyChangedEventArgs("NewCustomerLogo")); } } #endregion private Customer newCustomer = new Customer(); public Customer NewCustomer { get { return newCustomer; } set { newCustomer = value; OnPropertyChanged(new PropertyChangedEventArgs("NewCustomer")); } } #region PropertyChanged public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged(PropertyChangedEventArgs e) { if (PropertyChanged != null) PropertyChanged(this, e); } #endregion }