Ejemplo n.º 1
0
            private void Initialize()
            {
                isDynamicCodedValue     = false;
                isCodedValue            = false;
                isTypeIDField           = false;
                dynamicCodedValueSource = null;
                codedValueSources       = null;
                TypeIDField             = string.Empty;

                if (string.IsNullOrEmpty(_field) || _layerInfo == null)
                {
                    return;
                }

                TypeIDField = _layerInfo.TypeIdField;

                Field field = _layerInfo.Fields.FirstOrDefault(x => x.Name == _field);

                isDynamicCodedValue = FieldDomainUtils.IsDynamicDomain(field, LayerInfo);
                isCodedValue        = (field.Domain is CodedValueDomain);
                isTypeIDField       = (field.Name == TypeIDField);

                if (isDynamicCodedValue)
                {
                    dynamicCodedValueSource = FieldDomainUtils.BuildDynamicCodedValueSource(field, _layerInfo);
                }
                else if (isTypeIDField)
                {
                    codedValueSources = FieldDomainUtils.BuildTypeIDCodedValueSource(field, _layerInfo);
                }
                else if (isCodedValue)
                {
                    codedValueSources = FieldDomainUtils.BuildCodedValueSource(field);
                }
            }
        /// <summary>
        /// Sets the <see cref="FeatureDataGrid"/>'s ItemsSource after converting the source parameter to
        /// the proper format.
        /// </summary>
        /// <param name="graphics">The graphics.</param>
        private void SetItemsSource(IEnumerable <Graphic> graphics)
        {
            Dictionary <string, Field> fieldProps = null;
            string uniqueID = null;

            if (featureLayer == null)
            {
                featureLayer = GraphicsLayer as FeatureLayer;
            }
            if (featureLayer != null)
            {
                featureLayerInfo = featureLayer.LayerInfo;
                SetSubmitButtonVisibility();

                if (featureLayer.LayerInfo != null)
                {
                    fieldInfo = FieldDomainUtils.SetFieldInfo(featureLayerInfo, out rangeDomainInfo, out fieldProps);
                    uniqueID  = featureLayerInfo.ObjectIdField;
                }
            }
            else
            {
                fieldInfo       = null;
                rangeDomainInfo = null;
            }
            // Indicate that the ItemsSource is about to be created by setting the isCreatingItemsSource flag.
            // We have to do this for both Silverlight and WPF as PagedCollectionView and CollectionViewSource
            // always add the first object to their selection:
            isCreatingItemsSource = true;

            var enumerableGraphics = graphics.ToDataSource(fieldInfo, rangeDomainInfo, fieldProps, uniqueID, FilterSource, out objectType) as IEnumerable <object>;

            if (enumerableGraphics.Count <object>() == 0)
            {
                // use this when collection is empty, because it shows the column headers.
                // PagedCollectionView does not create the headers for the collection it contains
                // when the collection is empty.
                ItemsSource = enumerableGraphics;
            }
            else
            {
                ItemsSource = new PagedCollectionView(enumerableGraphics);
                (ItemsSource as PagedCollectionView).CollectionChanged += PagedCollectionView_CollectionChanged;
            }
            if (GraphicsLayer != null)
            {
                RestorePreviousSelection(GraphicsLayer.SelectedGraphics);
            }
            ShowNumberOfRecords();
        }
 /// <summary>
 /// Raises the <see cref="E:System.Windows.Controls.DataGrid.CellEditEnded"/> event.
 /// </summary>
 /// <param name="e">The event data.</param>
 protected override void OnCellEditEnded(DataGridCellEditEndedEventArgs e)
 {
     if (e.EditAction == DataGridEditAction.Commit)
     {
         Field field = e.Column.GetValue(FieldColumnProperty) as Field;
         if (field != null && featureLayer != null && featureLayer.LayerInfo != null)
         {
             if (field.Domain is CodedValueDomain ||
                 featureLayer.LayerInfo.TypeIdField == field.Name ||
                 FieldDomainUtils.IsDynamicDomain(field, featureLayer.LayerInfo))
             {
                 // When cell edit ends update the graphic with the cell change.
                 var xObject = e.Row.DataContext;
                 var graphic = DataSourceCreator.GetGraphicSibling(xObject);
                 xObject.RefreshGraphic(graphic, xObject.GetType());
             }
         }
     }
     base.OnCellEditEnded(e);
 }