Your code may be shorter:
<TextBlock ToolTip="{Binding PrideLands.YearsTillSimbaReturns, Converter={StaticResource convStringFormat}, ConverterParameter='Rejoice! Just {0} years left!'}" Text="Hakuna Matata"/>
We will use the fact that converters are never ignored, unlike StringFormat.
Put this in StringFormatConverter.cs :
using System; using System.Globalization; using System.Windows; using System.Windows.Data; namespace TLKiaWOL { [ValueConversion (typeof(object), typeof(string))] public class StringFormatConverter : IValueConverter { public object Convert (object value, Type targetType, object parameter, CultureInfo culture) { if (ReferenceEquals(value, DependencyProperty.UnsetValue)) return DependencyProperty.UnsetValue; return string.Format(culture, (string)parameter, value); } public object ConvertBack (object value, Type targetType, object parameter, CultureInfo culture) { throw new NotSupportedException(); } } }
Put this in your ResourceDictionary.xaml :
<conv:StringFormatConverter x:Key="convStringFormat"/>
Athari Dec 25 2018-12-12T00: 00Z
source share