/// <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); } } }
/// <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); } } }