Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# C Silverlight-延迟子窗口加载? 情景_C#_Silverlight - Fatal编程技术网

C# C Silverlight-延迟子窗口加载? 情景

C# C Silverlight-延迟子窗口加载? 情景,c#,silverlight,C#,Silverlight,目前我有一个C Silverlight应用程序,它使用domainservice类和ADO.Net实体框架与我的数据库通信。我想在单击按钮时加载一个子窗口,其中包含一些从服务器端查询检索到数据库的数据 过程 此过程的第一部分涉及两个加载操作,以从两个表中加载单独的数据。该过程的下一部分涉及组合这些数据列表以显示在列表框中 问题 问题是,在到达合并这些数据列表的代码段时,前两个异步加载操作尚未返回数据,因此导致空值异常 获取数据的初始加载操作: 然后我想立即执行此操作: 但是我不能,因为异步调用还

目前我有一个C Silverlight应用程序,它使用domainservice类和ADO.Net实体框架与我的数据库通信。我想在单击按钮时加载一个子窗口,其中包含一些从服务器端查询检索到数据库的数据

过程 此过程的第一部分涉及两个加载操作,以从两个表中加载单独的数据。该过程的下一部分涉及组合这些数据列表以显示在列表框中

问题 问题是,在到达合并这些数据列表的代码段时,前两个异步加载操作尚未返回数据,因此导致空值异常

获取数据的初始加载操作: 然后我想立即执行此操作: 但是我不能,因为异步调用还没有返回数据。。。 因此,我必须执行加载操作,然后按下子窗口上的按钮以执行列表连接和绑定: 解决方案的潜在想法: 以某种方式延迟子窗口的显示? 可能使用DomainDataSource和活动负载控制


非常感谢您的任何想法、帮助、解决方案、示例评论等。

首先,延迟显示窗口没有任何意义。相反,您应该将代码设计为能够处理数据的异步更新。在这种情况下,您会遇到一种有点有趣的情况,即您正在执行两个异步加载操作,并且您只能在两个操作都完成时创建数据以供显示

这个问题的一个解决方案是将合并数据的查询移动到服务器端。然后,您可以检索JobImageAudit对象,而不是通过两个单独的操作从服务器检索图像和审核对象

另一个解决方案是为检索的数据创建类似于视图模型的内容。下面是一个粗略的草图,让您开始:

public class JobImageAuditViewModel : INotifyPropertyChanged {

  IEnumerable<Image> images;

  IEnumerable<Audit> audits;

  IEnumerable<JobImageAudit> jobImageAudits;

  public void GetData() {
     this.images = null;
     this.audits = null;
     this.jobImageAudits = null;
     OnPropertyChanged("JobImageAuditList");
     // Load images by using GetImageByIDQuery()
     // Load audits by using GetAuditByJobIDQuery()
  }

  void LoadImageCompleted(Object sender, EventArgs e) {
    // Store result of query.
    this.images = ...
    UpdateJobImageAuditList();
  }

  void LoadAuditCompleted(Object sender, EventArgs e) {
    // Store result of query.
    this.audits = ...
    UpdateJobImageAudits();
  }

  void UpdateJobImageAudits() {
    if (this.images != null && this.jobs != null) {
      // Combine images and audits.
      this.jobImageAudits = ...
      OnPropertyChanged("JobImageAudits");
    }
  }

  public IEnumerable<JobImageAudit> JobImageAudits {
    get {
      return this.jobImageAudits; 
    }
  }

  public event PropertyChangedEventHandler PropertyChanged;

  protected virtual void OnPropertyChanged(String propertyName) {
    var handler = PropertyChanged;
    if (handler != null)
      handler(this, new PropertyChangedEventArgs(propertyName));
  }

}

实际上.NETRIA框架的设计目的是让客户端生成的实体类承担MVVM应用程序中视图模型的角色。它们可以在客户端进行扩展,并且支持INotifyPropertyChanged。但是,在您的情况下,您使用的是客户端上的实体,而服务器端不存在该实体。将我的第一个建议与数据绑定相结合可能是解决您问题的最终解决方案。

首先,延迟窗口的显示没有任何意义。相反,您应该将代码设计为能够处理数据的异步更新。在这种情况下,您会遇到一种有点有趣的情况,即您正在执行两个异步加载操作,并且您只能在两个操作都完成时创建数据以供显示

这个问题的一个解决方案是将合并数据的查询移动到服务器端。然后,您可以检索JobImageAudit对象,而不是通过两个单独的操作从服务器检索图像和审核对象

另一个解决方案是为检索的数据创建类似于视图模型的内容。下面是一个粗略的草图,让您开始:

public class JobImageAuditViewModel : INotifyPropertyChanged {

  IEnumerable<Image> images;

  IEnumerable<Audit> audits;

  IEnumerable<JobImageAudit> jobImageAudits;

  public void GetData() {
     this.images = null;
     this.audits = null;
     this.jobImageAudits = null;
     OnPropertyChanged("JobImageAuditList");
     // Load images by using GetImageByIDQuery()
     // Load audits by using GetAuditByJobIDQuery()
  }

  void LoadImageCompleted(Object sender, EventArgs e) {
    // Store result of query.
    this.images = ...
    UpdateJobImageAuditList();
  }

  void LoadAuditCompleted(Object sender, EventArgs e) {
    // Store result of query.
    this.audits = ...
    UpdateJobImageAudits();
  }

  void UpdateJobImageAudits() {
    if (this.images != null && this.jobs != null) {
      // Combine images and audits.
      this.jobImageAudits = ...
      OnPropertyChanged("JobImageAudits");
    }
  }

  public IEnumerable<JobImageAudit> JobImageAudits {
    get {
      return this.jobImageAudits; 
    }
  }

  public event PropertyChangedEventHandler PropertyChanged;

  protected virtual void OnPropertyChanged(String propertyName) {
    var handler = PropertyChanged;
    if (handler != null)
      handler(this, new PropertyChangedEventArgs(propertyName));
  }

}
实际上.NETRIA框架的设计目的是让客户端生成的实体类承担MVVM应用程序中视图模型的角色。它们可以在客户端进行扩展,并且支持INotifyPropertyChanged。但是,在您的情况下,您使用的是客户端上的实体,而服务器端不存在该实体。将我的第一个建议与数据绑定相结合可能是解决您的问题的最终解决方案

private void LoadAuditsButton_Click(object sender, RoutedEventArgs e)
        {

            IEnumerable<JobImageAudit> jobImageAuditList
                = from a in auditList
                  join ai in imageList
                  on a.ImageID equals ai.ImageID
                  select new JobImageAudit
                  {
                      JobID = a.JobID,
                      ImageID = a.ImageID.Value,
                      CreatedBy = a.CreatedBy,
                      CreatedDate = a.CreatedDate,
                      Comment = a.Comment,
                      LowResUrl = ai.LowResUrl,

                  };

            auditTrailList.ItemsSource = jobImageAuditList;
        }
public class JobImageAuditViewModel : INotifyPropertyChanged {

  IEnumerable<Image> images;

  IEnumerable<Audit> audits;

  IEnumerable<JobImageAudit> jobImageAudits;

  public void GetData() {
     this.images = null;
     this.audits = null;
     this.jobImageAudits = null;
     OnPropertyChanged("JobImageAuditList");
     // Load images by using GetImageByIDQuery()
     // Load audits by using GetAuditByJobIDQuery()
  }

  void LoadImageCompleted(Object sender, EventArgs e) {
    // Store result of query.
    this.images = ...
    UpdateJobImageAuditList();
  }

  void LoadAuditCompleted(Object sender, EventArgs e) {
    // Store result of query.
    this.audits = ...
    UpdateJobImageAudits();
  }

  void UpdateJobImageAudits() {
    if (this.images != null && this.jobs != null) {
      // Combine images and audits.
      this.jobImageAudits = ...
      OnPropertyChanged("JobImageAudits");
    }
  }

  public IEnumerable<JobImageAudit> JobImageAudits {
    get {
      return this.jobImageAudits; 
    }
  }

  public event PropertyChangedEventHandler PropertyChanged;

  protected virtual void OnPropertyChanged(String propertyName) {
    var handler = PropertyChanged;
    if (handler != null)
      handler(this, new PropertyChangedEventArgs(propertyName));
  }

}
ItemsSource="{Binding JobImageAudits}"