コード例 #1
0
        private void ObjectDataSource_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.IsInDesignTool)
            {
                return;
            }

            // Load event will fire when return to page during navigation.
            if (_controlLoaded)
            {
                return;
            }

            // Initialize ControlParameters in descriptors now.
            SortDescriptors.ForEach(s => s.Initialize(this, this.Culture));
            FilterDescriptors.ForEach(f => f.Initialize(this, this.Culture));
            GroupDescriptors.ForEach(g => g.Initialize(this, this.Culture));

            // We have to listen for changes.
            SortDescriptors.CollectionChanged   += SortDescriptors_CollectionChanged;
            SortDescriptors.ItemChanged         += SortDescriptors_ItemChanged;
            FilterDescriptors.ItemChanged       += FilterDescriptors_ItemChanged;
            FilterDescriptors.CollectionChanged += FilterDescriptors_CollectionChanged;
            GroupDescriptors.ItemChanged        += GroupDescriptors_ItemChanged;
            GroupDescriptors.CollectionChanged  += GroupDescriptors_CollectionChanged;

            if (AutoLoad)
            {
                LoadCore();
            }
            _controlLoaded = true;
        }
コード例 #2
0
        private void RefreshViewAfterSortChange()
        {
            var view = DataView as ICollectionView;

            view.SortDescriptions.Clear();
            SortDescriptors.ForEach(s => view.SortDescriptions.Add(s.ToSortDescription()));
            if (AutoLoad)
            {
                view.Refresh();
            }
        }
コード例 #3
0
        private void LoadView()
        {
            // Create and start loading the PCV.

            // Neither EQPCV nor PCV will work with anonymous types.
            if (AnonymousFns.IsAnonymousType(Query.ElementType))
            {
                throw new NotSupportedException("Anonymous types are not currently supported.  To work around this limitation, you can instead project into a custom type.");
            }

            if (IsEntityQuery)
            {
                EntityManager.GetEntityGroup(Query.ElementType).EntityChanged += ObjectDataSource_EntityChanged;
            }

            IsLoadingData = true;
            HasChanges    = false;

            // Convert from our "descriptors" to the "descriptions" known by a PCV.
            var sortFields = new SortDescriptionCollection();

            SortDescriptors.ForEach(s => sortFields.Add(s.ToSortDescription()));
            var groupFields = new ObservableCollection <GroupDescription>();

            GroupDescriptors.ForEach(g => groupFields.Add(g.ToGroupDescription()));

            // We'll use an EQPCV or PCV depending on a few factors: 1) an EntityQuery (so we can issue skip/take, 2) paging
            bool useEqpcv = Query is EntityQuery && PageSize > 0;

            if (useEqpcv)
            {
                EntityQueryPagedCollectionView pcv = null;
                var query  = Query as EntityQuery;
                var filter = GetQueryFilter();
                if (sortFields.Count > 0 || groupFields.Count > 0)
                {
                    pcv = new EntityQueryPagedCollectionView(query, PageSize, LoadSize, sortFields, groupFields, filter);
                }
                else
                {
                    pcv = new EntityQueryPagedCollectionView(query, PageSize, LoadSize, true, true);
                    pcv.SetQueryFilter(filter);
                    pcv.Refresh();
                }
                Data     = pcv;
                DataView = pcv;
            }
            else
            {
                // Use the standard PagedCollectionView (when paging isn't wanted or not an EntityQuery)
                IEntityQuery query = Query;
                if (Query is EntityQuery)
                {
                    query = GetFilteredQuery();
                }
                EntityManager.ExecuteQueryAsync(query, args => {
                    PagedCollectionView pcv = new PagedCollectionView(args.Results);
                    sortFields.ForEach(d => pcv.SortDescriptions.Add(d));
                    groupFields.ForEach(d => pcv.GroupDescriptions.Add(d));
                    pcv.PageSize = PageSize;
                    Data         = pcv;
                    DataView     = pcv;
                });
            }
        }