1

I would like to use design-time data for the DesignInstance of my WPF UI view. However, in order for the default constructor of the associated ViewModel to work, I need to read in some configuration information from an external file. (At runtime, I deserialize the information from json.)

The problem is, the ViewModel is not getting instantiated (so the design-time data is not showing up).

In an attempt to diagnose the problem, I used the attach-to-separate-process technique, so I could debug the DesignInstance. I confirmed that the constructor was failing at the point where it tries to create a FileStream to the external config file. I presume that the CurrentDirectory is not the same as when the application is actually running, and therefore the config file cannot be found. (I can set an absolute path and it works, but that solution isn't compatible with my development team, since the absolute path would be different for every developer.)

Is there another way to find the correct path?

kmote
  • 16,095
  • 11
  • 68
  • 91
  • do you really need to use real data at design time? Why not just initialize it with mock data? – Alex Butenko Jan 12 '18 at 03:03
  • @AlexButenko, good question, but the problem in this case is that this particular GUI represents a rather complex interface, so the code for mocking it up would be fairly extensive. I had the same problem with the unit tests, which is how I started storing the mock data in a json config file. So now I would like to reuse those files, but I can't figure out how to access them. – kmote Jan 12 '18 at 16:12

0 Answers0