/// <summary> /// Modifies the source data before passing it to the target for display in the UI. /// </summary> /// <param name="value">The source data being passed to the target.</param> /// <param name="targetType">The <see cref="T:System.Type"/> of data expected by the target dependency property.</param> /// <param name="parameter">An optional parameter to be used in the converter logic.</param> /// <param name="culture">The culture of the conversion.</param> /// <returns> /// The value to be passed to the target dependency property. /// </returns> public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (parameter == null || string.IsNullOrEmpty(Field) || value == null) { return(""); } #if SILVERLIGHT PropertyInfo fieldProperty = value.GetType().GetProperty(Field); if (fieldProperty == null) { return(""); } var code = fieldProperty.GetValue(value, null); #else var code = value; #endif if (code == null) { return(""); } CodedValueSources codedValueSources = parameter as CodedValueSources; if (codedValueSources != null) { CodedValueSource codedValueSource = codedValueSources.FirstOrDefault(x => x.Code != null && x.Code.ToString() == code.ToString()); if (codedValueSource != null) { return(codedValueSource.DisplayName); } } return(""); }
/// <summary> /// Returns a CodedValueSources object constructed form the CodedValueDomain value. /// </summary> /// <param name="field">The field to make a CodedValueSource from.</param> /// <returns>The CodedValueSources object used for a code to value lookup.</returns> internal static CodedValueSources BuildCodedValueSource(Field field) { CodedValueDomain codedValueDomain = field.Domain as CodedValueDomain; CodedValueSources codedValueSources = null; if (codedValueDomain != null) { foreach (KeyValuePair <object, string> codedValue in codedValueDomain.CodedValues) { if (codedValueSources == null) { codedValueSources = new CodedValueSources(); if (field.Nullable) { CodedValueSource nullableSource = new CodedValueSource() { Code = null, DisplayName = " " }; codedValueSources.Add(nullableSource); } } codedValueSources.Add(new CodedValueSource() { Code = codedValue.Key, DisplayName = codedValue.Value }); } } return(codedValueSources); }
/// <summary> /// Returns CodedValueSources that make up the display text of each value of the TypeIDField. /// </summary> /// <param name="field">TypeIDField</param> /// <param name="layerInfo">FeatureLayerInof used to construct the CodedValueSources from the FeatureTypes.</param> /// <returns>CodedValueSoruces that contain code an value matches to all possible TypeIDField values.</returns> internal static CodedValueSources BuildTypeIDCodedValueSource(Field field, FeatureLayerInfo layerInfo) { CodedValueSources codedValueSources = null; foreach (KeyValuePair <object, FeatureType> kvp in layerInfo.FeatureTypes) { if (kvp.Key == null) { continue; } string name = (kvp.Value != null && kvp.Value.Name != null) ? kvp.Value.Name : ""; CodedValueSource codedValueSource = new CodedValueSource() { Code = kvp.Key, DisplayName = name }; if (codedValueSources == null) { codedValueSources = new CodedValueSources(); if (field.Nullable) { CodedValueSource nullableSource = new CodedValueSource() { Code = null, DisplayName = " " }; codedValueSources.Add(nullableSource); } } codedValueSources.Add(codedValueSource); } return(codedValueSources); }
/// <summary> /// Builds a DynamicCodedValueSource object used to lookup display value. /// </summary> /// <param name="field">The field to build DynamicCodedValueSource for</param> /// <param name="layerInfo">The FeatureLayerInfo used to lookup all the coded value domains </param> /// <returns>DynamicCodedValueSource which is a collection of coded value domain values for a field.</returns> internal static DynamicCodedValueSource BuildDynamicCodedValueSource(Field field, FeatureLayerInfo layerInfo) { DynamicCodedValueSource dynamicCodedValueSource = null; foreach (object key in layerInfo.FeatureTypes.Keys) { FeatureType featureType = layerInfo.FeatureTypes[key]; if (featureType.Domains.ContainsKey(field.Name)) { if (dynamicCodedValueSource == null) { dynamicCodedValueSource = new DynamicCodedValueSource(); } CodedValueDomain codedValueDomain = featureType.Domains[field.Name] as CodedValueDomain; if (codedValueDomain != null) { CodedValueSources codedValueSources = null; foreach (KeyValuePair <object, string> kvp in codedValueDomain.CodedValues) { if (codedValueSources == null) { codedValueSources = new CodedValueSources(); if (field.Nullable) { CodedValueSource nullableSource = new CodedValueSource() { Code = null, DisplayName = " " }; codedValueSources.Add(nullableSource); } } codedValueSources.Add(new CodedValueSource() { Code = kvp.Key, DisplayName = kvp.Value }); } if (codedValueSources != null) { if (dynamicCodedValueSource == null) { dynamicCodedValueSource = new DynamicCodedValueSource(); } dynamicCodedValueSource.Add(featureType.Id, codedValueSources); } } } } return(dynamicCodedValueSource); }
internal static CodedValueSources GetCodedValueSources(string lookupField, Field field, object generic, DynamicCodedValueSource dynamicCodedValueSource, CodedValueSources nullableSources) { if (dynamicCodedValueSource != null && generic != null && !string.IsNullOrEmpty(lookupField)) { #if SILVERLIGHT PropertyInfo lookupFieldProperty = generic.GetType().GetProperty(lookupField); if (lookupFieldProperty == null) { return(null); } var key = lookupFieldProperty.GetValue(generic, null); #else var key = (generic is Graphic) ? (generic as Graphic).Attributes[lookupField] : null; #endif if (key == null) { object code = CodedValueSources.CodedValueCodeLookup(field.Name, generic, new CodedValueSources()); nullableSources.Clear(); if (field.Nullable) { CodedValueSource nullableSource = new CodedValueSource() { Code = null, DisplayName = " " }; nullableSources.Add(nullableSource); } if (code != null) { CodedValueSource currentSource = new CodedValueSource() { Code = code, DisplayName = code.ToString() }; nullableSources.Add(currentSource); } return(nullableSources); } CodedValueSources codedValueSoruces = null; if (dynamicCodedValueSource.ContainsKey(key)) { codedValueSoruces = dynamicCodedValueSource[key]; } else if (dynamicCodedValueSource.ContainsKey(key.ToString())) { codedValueSoruces = dynamicCodedValueSource[key.ToString()]; } CodedValueSource tempSource = codedValueSoruces.FirstOrDefault(x => x.Temp == true); if (tempSource != null) { codedValueSoruces.Remove(tempSource); } #if SILVERLIGHT object value = CodedValueSources.CodedValueNameLookup(field.Name, generic, new CodedValueSources()); if (string.IsNullOrEmpty(value as string)) { value = null; } #else object value = (generic as Graphic).Attributes[field.Name]; #endif if (value != null) { CodedValueSource source = codedValueSoruces.FirstOrDefault(x => x.Code != null && x.Code.ToString() == value.ToString()); if (source == null) { CodedValueSource currentSource = new CodedValueSource() { Code = value, DisplayName = value.ToString(), Temp = true }; if (field.Nullable) { codedValueSoruces.Insert(1, currentSource); } else { codedValueSoruces.Insert(0, currentSource); } } } return(codedValueSoruces); } return(null); }