Asynchronously loading Blendable sample data in MVVM Light in the view model's constructor

前端 未结 1 420
广开言路
广开言路 2021-01-24 04:11

I have a Windows Phone 8.1 MVVM Light project and I am struggling to keep it Blendable.

As I see it I have a few options. I can load different view mode

1条回答
  •  一向
    一向 (楼主)
    2021-01-24 04:44

    Load your data on the page load event, using a Command, so you can take advantage of the await/async stuff. I don't know how this works with blend as I don't use it much.

    View:

    
        
            
           
    
    

    ViewModel:

    public RelayCommand PageLoadedCommand { get; private set; }
    public MyConstructor(IService serviceInjected)
    {
        PageLoadedCommand = new RelayCommand(async()=>await OnPageLoaded());
    ....
    }
    
    private async Task OnPageLoaded()
    {
       if(ViewModelBase.IsInDesignModeStatic)
       {
           var data = await GetSampleDataAsync();
           //Do something..
       }
    }
    

    0 讨论(0)
提交回复
热议问题