在Silverlight中实现MVVM:异步执行问题

在Silverlight中实现MVVM:异步执行问题,silverlight,mvvm,Silverlight,Mvvm,嗨,我面临一个问题,找不到合适的解决方案。 在我看来,我有几个组合框需要从Viewmodel填充。视图的数据内容定义如下: <navigation:Page.Resources> <viewModel:TheViewModel x:Key="viewModel"/> </navigation:Page.Resources> <navigation:Page.DataContext> <Binding Source="{Sta

嗨,我面临一个问题,找不到合适的解决方案。 在我看来,我有几个组合框需要从Viewmodel填充。视图的数据内容定义如下:

<navigation:Page.Resources>
    <viewModel:TheViewModel x:Key="viewModel"/>
</navigation:Page.Resources>

<navigation:Page.DataContext>
    <Binding Source="{StaticResource viewModel}"/>
</navigation:Page.DataContext>

然后在ViewModel构造函数中,我有如下代码:

LoadOperation<ProducType> loadPT = context.Load(context.GetProducTypeQuery());
    loadPT.Completed += (sender1, e1) => {
        if (!loadPT.HasError) {
            LoadOperation<Client> loaC = context.Load(context.GetClientQuery());
                loaC .Completed += (sender2, e2) => {
                    if (!loaC.HasError) {
                        ProducTypes = loadPT.Entities;
                        Clients= loaC.Entities;   
                        Remitentes = loadr.Entities;
                     }
                  };
         }
    };
LoadOperation loadPT=context.Load(context.GetProducTypeQuery());
loadPT.Completed+=(发送方1,e1)=>{
如果(!loadPT.HasError){
LoadOperation loaC=context.Load(context.GetClientQuery());
loaC.已完成+=(发送者2,e2)=>{
如果(!loaC.HasError){
ProducTypes=loadPT.Entities;
客户=贷款实体;
汇款人=收款人实体;
}
};
}
};
在这个配置中,我遇到了一个问题,我的组合框永远不会被填充,因为对于Silverlight的异步模型,当框架完成创建视图时,上面的代码还没有执行。 我相信这一定是我的一些知识的缺乏,我在Porgaming不是新的,但在silverlight非常新,任何帮助,请将不胜感激 塔克斯
Elio

我的ViewModels派生自实现INotifyPropertyChanged的基类。我将组合框绑定到ViewModel上的公共属性。放置异步调用以获取属性getter中的数据

下面是一个例子:

视图模型:

public class MyViewModel : BaseViewModel
{
    private List<MyObject> _myObjectlist;
    public List<MyObject> MyObjectList
    {
         get
         {
             if (_myObjectList == null)
             {
                  _ctx.Load(q=>{
                        _myObjectList = q.Value;
                        //INotifyPropertyChanged implementation
                        RaisePropertyChanged("MyObjectList"); 
                   },null);
             }
         }
    }
}
公共类MyViewModel:BaseViewModel { 私有列表(myObjectlist);; 公共列表MyObjectList { 得到 { 如果(_myObjectList==null) { _ctx.Load(q=>{ _myObjectList=q.值; //INotifyPropertyChanged实现 RaisePropertyChanged(“MyObjectList”); },空); } } } }
My ViewModels派生自实现INotifyPropertyChanged的基类。我将组合框绑定到ViewModel上的公共属性。放置异步调用以获取属性getter中的数据

下面是一个例子:

视图模型:

public class MyViewModel : BaseViewModel
{
    private List<MyObject> _myObjectlist;
    public List<MyObject> MyObjectList
    {
         get
         {
             if (_myObjectList == null)
             {
                  _ctx.Load(q=>{
                        _myObjectList = q.Value;
                        //INotifyPropertyChanged implementation
                        RaisePropertyChanged("MyObjectList"); 
                   },null);
             }
         }
    }
}
公共类MyViewModel:BaseViewModel { 私有列表(myObjectlist);; 公共列表MyObjectList { 得到 { 如果(_myObjectList==null) { _ctx.Load(q=>{ _myObjectList=q.值; //INotifyPropertyChanged实现 RaisePropertyChanged(“MyObjectList”); },空); } } } }