Quantcast
Viewing all articles
Browse latest Browse all 18858

WPF: How to dynamically change the image source and how to ensure that the image files are exist?

We see the following link example about how to do dynamically updating image source
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/d3d44031-0b0a-4d39-a10b-20aba3a07d6e/

We have implemented a different way so far.
In viewmodel class, we define a string property
public string ImageSourcePath
    {
      get {
        Model model = SManager.Model;
       Switch (model)
        case Model.One:
         return "pack://application:,,,/ResourcesLibrary;component/Images/ModelOne.png";
        case Model.Two:
          return "pack://application:,,,/ResourcesLibrary;component/Images/ModelTwo.png";
        case Model.AnalyticalInterference:
         default:
          return "pack://application:,,,/ResourcesLibrary;component/Images/ModelThree.png";
        }
      }
    }
In xamle, we simply binding image source to the above property:
<Image x:Name="Imagexxx"
                    Source="{Binding Path=ImageSourcePath}"
                     />
It works great! The only problem we see so far, if you type a wrong image file name, it will not detect it in compiler time,
It will crash in run time.

We have define all those image files in the separated assembly and set the build action as "Resource" for those image files.
We thought that one thing we can do is to using VS unit testing to ensure those image files are existed in the separted folder.
If we create unit testing for checking those image files if existed, how can we test it after build.
After builing the release, those files will not in the folder we think since they binding to the ResourcesLibrary.dll,
how do we testing it?
thanks,
Jane

Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>