2

Today, I tried to implement View-Model asynchronously. I found this article. In that moment I thought that it is not so easy I imagined...

I understand why it works. But unfortunately, it is impossible to use this code when I want to mock my design-time data of view-models with Blend (mocking using SampleData.xaml), because Blend doesn't allow to mock generic data this way. So I thought about some refactor like this one:

public IEnumerable<MyModelType> Data { get { return _task.Result; } }
private NotifyTaskCompletion<IEnumerable<MyModelType>> _task;

and calling Data from XAML instead of calling Task.Result.

Now I can mock everything again, but when I run the code, I didn't get my data the most times, because the Task had WaitingForActivation status. I don't understand the mechanism in each detail, but after a bit of Googling I got that I should use async/await syntax. It does make sense of course, but I can't do this because my Data is a property and it can't be async. And it doesn't make sense for me.

Do you have any workaround (or pretty solution) for my issue?

There is the second way of mocking design-time data using IsInDesignMode (part of MVVM Light). What do you think about this second way of mocking? Does it solve my problem? When I think about this solution, I think it works in so strange way: it should compile my program with entire code and setting this property to false, but the condition is still always checked. Isn't it? If not, how does it actualy work?

pt12lol
  • 2,332
  • 1
  • 22
  • 48

0 Answers0