0

I'm developing a Windows Universal App and in one of my views I'm trying to use DesignTime Data. In my ViewModel i created a condition for loading real or dummy data:

if(IsInDesignModeStatic || IsInDesignMode)
{
    var service = new DummyService()

    this.Data = await service.GetInformation(null, null);
}

I'm using mvvmLight. The GetInformation Method of the service should load the data from a json file located in the project folder. I tried loading the file via "StorageFile.GetFileFromApplicationUriAsync(dataUri);" and via normal "File.ReadAllText". In both cases the Designer throws a "FileNotFoundException".

I also tried to debug the design time view model with another instance of visual studio, but i can't figure out which path should i use. I know that the designer is running in a separate process - XDesProc - but I'm not sure how my file path should look like so the XDesProc can find it.

So how can i load a file in code for design time data?

Sven Lauterbach
  • 400
  • 2
  • 16

1 Answers1

0

For design time data I would suggest to use hardcoded values. Take a look at this article (although it's not specific to uwp, imho everything applies to your case: )

https://msdn.microsoft.com/en-us/magazine/dn169081.aspx

especially this part:

But some operations (for example, certain complex multithreaded operations and operations that use a path relative to the application’s assembly) can cause an inner exception

So like the article use static data and if you want to make it fancy use the SimpleIoc to switch between design time and runtime data..

gregkalapos
  • 3,529
  • 2
  • 19
  • 35