public override object OnConvert(object value, Type targetType, object parameter, string language) { var text = value as string; if (string.IsNullOrEmpty(text)) { return(string.Empty); } if (text.Contains("<Inline>") && text.Contains("</Inline>")) { // We can have multiple inlined localized texts in the string... We have to remove // them all text = "<Inline>" + text.Replace("<Inline>", "").Replace("</Inline>", "") + "</Inline>"; var textBlock = new TextBlock(); textBlock.Inlines.Clear(); textBlock.Inlines.Add(XAMLHelper.ParseToInline(text)); textBlock.VerticalAlignment = VerticalAlignment.Stretch; textBlock.HorizontalAlignment = HorizontalAlignment.Stretch; textBlock.TextWrapping = TextWrapping.Wrap; textBlock.TextTrimming = TextTrimming.None; textBlock.TextAlignment = TextAlignment.Justify; textBlock.MaxWidth = 350; return(textBlock); } return(text); }
private static void OnToolTipChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args) { if (XAMLHelper.GetIsInDesignMode(dependencyObject)) { return; } var value = args.NewValue as string; var text = string.IsNullOrEmpty(value) ? string.Empty : Locale.Current[value]; var frameworkElement = dependencyObject as FrameworkElement; if (frameworkElement == null) { return; } if (text.StartsWith("<Inline>") && text.EndsWith("</Inline>")) { var textBlock = new TextBlock(); textBlock.Inlines.Clear(); textBlock.Inlines.Add(XAMLHelper.ParseToInline(text)); textBlock.VerticalAlignment = VerticalAlignment.Stretch; textBlock.HorizontalAlignment = HorizontalAlignment.Stretch; textBlock.TextWrapping = TextWrapping.Wrap; textBlock.TextTrimming = TextTrimming.None; textBlock.TextAlignment = TextAlignment.Justify; textBlock.MaxWidth = 350; #if WINDOWS_UWP ToolTipService.SetToolTip(frameworkElement, textBlock); #else frameworkElement.ToolTip = textBlock; #endif } else #if WINDOWS_UWP { ToolTipService.SetToolTip(frameworkElement, text); } #else { frameworkElement.ToolTip = text; } #endif }
private static void OnTextChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args) { var newValue = args.NewValue as string; var text = string.IsNullOrEmpty(newValue) ? string.Empty : (newValue.StartsWith("<Inline>") && newValue.EndsWith("</Inline>") ? newValue : Locale.Current[newValue]); if (dependencyObject is TextBlock) { var textBlock = dependencyObject as TextBlock; if (text.StartsWith("<Inline>") && text.EndsWith("</Inline>")) { textBlock.Inlines.Clear(); textBlock.Inlines.Add(XAMLHelper.ParseToInline(text)); } else { textBlock.Text = text; } } #if WINDOWS_UWP else if (dependencyObject is TextBox) { var element = dependencyObject as TextBox; element.Header = text; } else if (dependencyObject is ComboBox) { var element = dependencyObject as ComboBox; element.Header = text; } else if (dependencyObject is ButtonBase) { (dependencyObject as ButtonBase).Content = text; } #else else if (dependencyObject is HeaderedContentControl) { (dependencyObject as HeaderedContentControl).Header = text; } else if (dependencyObject is HeaderedItemsControl) { (dependencyObject as HeaderedItemsControl).Header = text; } else if (dependencyObject is GridViewColumn) { (dependencyObject as GridViewColumn).Header = text; } #endif else if (dependencyObject is ContentControl) { (dependencyObject as ContentControl).Content = text; } else { // We just try to get a title property - this will not work in UWP Native var title = dependencyObject.GetType().GetProperty("Title", BindingFlags.Public | BindingFlags.Instance); if (title != null) { title.SetValue(dependencyObject, text); } } }
private static void OnTextChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args) { if (XAMLHelper.GetIsInDesignMode(dependencyObject)) { return; } var newValue = args.NewValue as string; var text = string.IsNullOrEmpty(newValue) ? string.Empty : (newValue.StartsWith("<Inline>") && newValue.EndsWith("</Inline>") ? newValue : Locale.Current[newValue]); if (dependencyObject is TextBlock) { var textBlock = dependencyObject as TextBlock; if (text.StartsWith("<Inline>") && text.EndsWith("</Inline>")) { textBlock.Inlines.Clear(); textBlock.Inlines.Add(XAMLHelper.ParseToInline(text)); } else { textBlock.Text = text; } } #if WINDOWS_UWP else if (dependencyObject is TextBox) { var element = dependencyObject as TextBox; element.Header = text; } else if (dependencyObject is ComboBox) { var element = dependencyObject as ComboBox; element.Header = text; } else if (dependencyObject is ButtonBase) { (dependencyObject as ButtonBase).Content = text; } #else else if (dependencyObject is HeaderedContentControl) { (dependencyObject as HeaderedContentControl).Header = text; } else if (dependencyObject is HeaderedItemsControl) { (dependencyObject as HeaderedItemsControl).Header = text; } else if (dependencyObject is GridViewColumn) { (dependencyObject as GridViewColumn).Header = text; } #endif else if (dependencyObject is ContentControl) { (dependencyObject as ContentControl).Content = text; } Localized.SetLocalizedText(dependencyObject, text); }