Пример #1
0
        /// <summary>
        /// This method is used to create the UI for the FeatureDataField.
        /// </summary>
        private void Refresh()
        {
            // if the content control template part is missing then draw nothing.
            if (_contentControl == null)
            {
                return;
            }

            // attempt retrive the field info for our control
            _fieldInfo = GeodatabaseFeature.GetFieldInfo(FieldName);

            // if field information was not obtain then draw nothing.
            if (_fieldInfo == null)
            {
                return;
            }

            // Get the value from the GeodatabaseFeature if the attribute exists.
            BindingValue = GeodatabaseFeature.Attributes.ContainsKey(FieldName) ? GeodatabaseFeature.Attributes[FieldName] : null;

            // If the FeatureDataField.IsReadOnly property has been set to true or the FieldInfo
            if (IsReadOnly || !_fieldInfo.IsEditable)
            {
                switch (_fieldInfo.Type)
                {
                case FieldType.String:
                case FieldType.Double:
                case FieldType.Single:
                case FieldType.SmallInteger:
                case FieldType.Integer:
                case FieldType.Date:
                case FieldType.GlobalID:
                case FieldType.Guid:
                case FieldType.Oid:
                    GenerateReadonlyField();
                    break;

                case FieldType.Raster:
                case FieldType.Geometry:
                case FieldType.Unknown:
                case FieldType.Xml:
                case FieldType.Blob:
                    Visibility = Visibility.Collapsed;
                    break;
                }
            }
            else if (_fieldInfo.Domain is CodedValueDomain)
            {
                // Create selector UI
                GenerateSelectorField();
            }
            else
            {
                switch (_fieldInfo.Type)
                {
                case FieldType.String:
                    GenerateInputField();
                    break;

                case FieldType.Double:
                case FieldType.Single:
                case FieldType.SmallInteger:
                case FieldType.Integer:
                    GenerateInputField();
                    break;

                case FieldType.Date:
                    GenerateInputField();
                    break;

                case FieldType.GlobalID:
                case FieldType.Guid:
                case FieldType.Oid:
                    GenerateReadonlyField();
                    break;

                case FieldType.Raster:
                case FieldType.Geometry:
                case FieldType.Unknown:
                case FieldType.Xml:
                case FieldType.Blob:
                    Visibility = Visibility.Collapsed;
                    break;
                }
            }
        }
        /// <summary>
        /// Creates the UI of the entire control
        /// </summary>
        private void Refresh()
        {
            if (_controlRoot == null)
            {
                return;
            }

            // Clear root element children.
            _controlRoot.Children.Clear();
            _controlRoot.ColumnDefinitions.Clear();

            if (_editFeature != null && GeodatabaseFeature.Schema != null && Fields != null)
            {
                foreach (var control in _fieldControls.Keys.Select(key => _fieldControls[key]).OfType <FeatureDataField>())
                {
                    control.PropertyChanged -= ControlOnPropertyChanged;
                }
                _fieldControls.Clear();
                HasEdits = false;
                HasError = false;

                // Get collection of fields with supported field types.
                var supportedFields = _editFeature.Schema.Fields.Where(fieldInfo => !_notSupportFieldTypes.Contains(fieldInfo.Type));

                if (Fields == null || !Fields.Any())
                {
                    // default to only editable fields
                    var editableSupportedFields = supportedFields.Where(fieldInfo => fieldInfo.IsEditable);
                    _validFieldNames = editableSupportedFields.Select(fieldInfo => fieldInfo.Name);
                }
                else
                {
                    _validFieldNames = Fields.Contains("*")
                        ? supportedFields.Select(fieldInfo => fieldInfo.Name)                        // All Fields (*)
                        : Fields.Intersect(from fieldInfo in supportedFields select fieldInfo.Name); // specific fields provided by user
                }

                // Create UI for each field
                foreach (var fieldName in _validFieldNames)
                {
                    // Get the field information from schema for this field.
                    var fieldInfo = _editFeature.GetFieldInfo(fieldName);

                    // default the label text to field alias if not null or empty
                    var labelText = !string.IsNullOrEmpty(fieldInfo.Alias)
                        ? fieldInfo.Alias
                        : fieldInfo.Name;

                    var          isReadOnly       = false; // default readonly to false
                    Style        labelStyle       = null;
                    Style        containerStyle   = null;
                    DataTemplate inputTemplate    = null;
                    DataTemplate dateTimeTemplate = null;


                    // if user has wired into the on generating event we will expose
                    // some overridable information for each field.
                    if (GeneratingField != null)
                    {
                        // Create a new event argument for field.
                        var args = new GeneratingFieldEventArgs(fieldName, labelText, fieldInfo.Type)
                        {
                            IsReadOnly = IsReadOnly
                        };

                        // Raise the event for user
                        GeneratingField(this, args);

                        // If user changed the label text or set the
                        // field to read-only then we will use these
                        // during UI creation.
                        labelText        = args.LabelText;
                        isReadOnly       = args.IsReadOnly;
                        labelStyle       = args.LabelStyle;
                        inputTemplate    = args.InputTemplate;
                        dateTimeTemplate = args.DateTimeTemplate;
                        containerStyle   = args.ContainerStyle;
                    }

                    // create label ui
                    var label = CreateLabel(labelText);
                    label.Style = labelStyle ?? LabelStyle;

                    // create edit control ui
                    var control = CreateControl(_editFeature, fieldInfo, IsReadOnly ? IsReadOnly : isReadOnly);

                    if (fieldInfo.Type == FieldType.Date)
                    {
                        // Form or Field override of input template property.
                        if (dateTimeTemplate != null || DateTimeTemplate != null)
                        {
                            ((FeatureDataField)control).InputTemplate = dateTimeTemplate ?? DateTimeTemplate;
                        }
                        else if (inputTemplate != null || InputTemplate != null)
                        {
                            ((FeatureDataField)control).InputTemplate = inputTemplate ?? InputTemplate;
                        }
                    }
                    else
                    {
                        // Form or Field override of input template property.
                        if (inputTemplate != null || InputTemplate != null)
                        {
                            ((FeatureDataField)control).InputTemplate = inputTemplate ?? InputTemplate;
                        }
                    }

                    // create container control
                    var container = CreateContainer();
                    container.Style = containerStyle ?? ContainerStyle;

                    // Add label and edit control to container
                    container.Children.Add(label);
                    container.Children.Add(control);

                    // Set the Grid.Row attached property to the container
                    Grid.SetRow(container, _controlRoot.RowDefinitions.Count);

                    // Create a new RowDefinition for the container
                    _controlRoot.RowDefinitions.Add(new RowDefinition {
                        Height = GridLength.Auto
                    });

                    // Add each edit control to a lookup table that can be used
                    // to invoke save and cancel commands on FeatureDataField.
                    _fieldControls.Add(fieldName, control);

                    // Add continer to the Grid
                    _controlRoot.Children.Add(container);
                }
            }
        }