0

提前感谢您的帮助。我一直在使用此处列出的教程,但遇到了问题。我正在尝试在 Silverlight 中填充数据网格,但是当我提交按钮单击时,它将返回列的标题但没有数据。我知道数据在系统中,所以我很困惑为什么它会获取标题而不是要填充的实际数据。我的 MainPage.xaml.cs 和我的数据域中的代码如下。

MainPage.xaml.cs

namespace SandCherryDemo
{
    public partial class MainPage : UserControl
    {
        private SandCherryViewContext _sandCherryContext = new SandCherryViewContext();

        public MainPage()
        {
            InitializeComponent();
        }

        private void StatusButton_Click(object sender, RoutedEventArgs e)
        {
            StatusButton.IsEnabled = false;
            LoadOperation<SandCherryView> loadOp = this._sandCherryContext.Load(this._sandCherryContext.GetEQPByStatusQuery(StatusValue.Text), DataLoadedCallback, null);
            SandCherryGrid.ItemsSource = loadOp.Entities;
        }

        void DataLoadedCallback(LoadOperation<SandCherryView> loadOperation)
        {
            StatusButton.IsEnabled = true;
        }
    }
}

SandCherryViewService.cs

 [EnableClientAccess()]
    public class SandCherryViewService : LinqToEntitiesDomainService<Charter_SandCherryEntities>
    {
        [Query(IsComposable=false)]
        public IQueryable<SandCherryView> GetEQPByStatus(string status)
        {
            return this.ObjectContext.SandCherryViews.Where(e => e.StatusDescr.StartsWith(status) == true);
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'SandCherryViews' query.
        public IQueryable<SandCherryView> GetSandCherryViews()
        {
            return this.ObjectContext.SandCherryViews;
        }

        public void InsertSandCherryView(SandCherryView sandCherryView)
        {
            if ((sandCherryView.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(sandCherryView, EntityState.Added);
            }
            else
            {
                this.ObjectContext.SandCherryViews.AddObject(sandCherryView);
            }
        }

        public void UpdateSandCherryView(SandCherryView currentSandCherryView)
        {
            this.ObjectContext.SandCherryViews.AttachAsModified(currentSandCherryView, this.ChangeSet.GetOriginal(currentSandCherryView));
        }

        public void DeleteSandCherryView(SandCherryView sandCherryView)
        {
            if ((sandCherryView.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(sandCherryView, EntityState.Deleted);
            }
            else
            {
                this.ObjectContext.SandCherryViews.Attach(sandCherryView);
                this.ObjectContext.SandCherryViews.DeleteObject(sandCherryView);
            }
        }
    }
}
4

1 回答 1

0

由于您的数据尚未加载。尝试在事件中设置ItemsSource您的网格-DataLoadedCallBack

void DataLoadedCallback(LoadOperation<SandCherryView> loadOperation)
{
   StatusButton.IsEnabled = true;
   SandCherryGrid.ItemsSource = loadOp.Entities;
}
于 2012-10-02T16:47:11.913 回答