/// <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) { IDictionary <string, object> dict = null; PopupItem popupitem = null; if (value is PopupItem) { popupitem = value as PopupItem; if (popupitem != null && popupitem.Graphic != null) { dict = popupitem.Graphic.Attributes; } } if (dict != null) { string fieldName = parameter as string; if (!string.IsNullOrEmpty(fieldName)) { object o = MapTipsHelper.GetFieldValue(popupitem, fieldName); if (o != null) { return(o.ToString()); } } } return(null); }
const string attributeBindingRegex = @"({)([^}]*)(})"; // Regular expression to identify attribute bindings public static string ConvertExpressionWithFieldNames(PopupItem item, string formatter) { if (!string.IsNullOrEmpty(formatter)) { StringBuilder sb = new StringBuilder(); string[] splitStringArray = Regex.Split(formatter, attributeBindingRegex); bool isAttributeName = false; foreach (string str in splitStringArray) { if (str == "{") { isAttributeName = true; continue; } if (str == "}") { isAttributeName = false; continue; } if (isAttributeName && item.Graphic.Attributes.ContainsKey(str)) { var temp = MapTipsHelper.GetFieldValue(item, str); sb.AppendFormat("{0}", temp); } else if (!isAttributeName) { sb.AppendFormat("{0}", str); } } return(sb.ToString().Replace("$LINEBREAK$", "<br/>").Replace("&", "&").Replace("<", "<").Replace(">", ">").Replace("'", "'").Replace(""", "\"")); } return(null); }
/// <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) { IDictionary <string, object> dict = null; PopupItem popupitem = null; if (value is PopupItem) { popupitem = value as PopupItem; if (popupitem != null && popupitem.Graphic != null) { dict = popupitem.Graphic.Attributes; } } if (dict != null) { object fieldValue = null; string fieldName = parameter as string; if (!string.IsNullOrEmpty(fieldName)) { fieldValue = MapTipsHelper.GetFieldValue(popupitem, fieldName); } if (fieldValue != null) { string fieldUrl = MapTipsHelper.ExtractHyperlinkValue(fieldValue, true); if (String.IsNullOrEmpty(fieldUrl)) { return(null); } Uri targetUri = null; if (!Uri.TryCreate(fieldUrl, UriKind.Absolute, out targetUri)) { return(null); } return(fieldUrl); } } return(null); }