A number of different approaches may exist depending on your requirement. The following is a very general solution.
Create a value converter that converts the string to type: -
public class StringToTypeConverter : IValueConverter
{
#region IValueConverter Members
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return Type.GetType((string)value);
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
#endregion
}
Put an instance of this converter in the resource dictionary for which the target object is visible, say, App.xaml: -
<Application.Resources>
<local:StringToTypeConverter x:Key="STT" />
</Application.Resources>
Now in your Xaml you can assign a value to the following properties: -
<TextBox Text="{Binding Source='System.Int32,mscorlib', Converter={StaticResource STT}}" />
source
share