You'll need to use an IValueConverter
to do this.
[ValueConversion(typeof(object), typeof(string))]
public class ObjectToTypeConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return value == null ? null : value.GetType().Name // or FullName, or whatever
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new InvalidOperationException();
}
}
Then add it to your resources...
<Window.Resources>
<my:ObjectToTypeConverter x:Key="typeConverter" />
</Window.Resources>
Then use it on your binding
<TextBlock Text="{Binding Mode=OneWay, Converter={StaticResource typeConverter}}" />
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…