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