Datagrid没有填充过去的标题

时间:2012-10-02 16:35:53

标签: c# database silverlight datagrid

提前感谢您的帮助。我一直在使用列出here的教程,但遇到了一个问题。我正在尝试在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);
            }
        }
    }
}

1 个答案:

答案 0 :(得分:0)

由于您的数据尚未加载。尝试在ItemsSource事件 -

中设置网格的DataLoadedCallBack
void DataLoadedCallback(LoadOperation<SandCherryView> loadOperation)
{
   StatusButton.IsEnabled = true;
   SandCherryGrid.ItemsSource = loadOp.Entities;
}