I'd like to know how I can assign in XAML a dependency property of type Type in Silverlight since the markup extension {x:Type} does not exist ?
Thanks,
I'd like to know how I can assign in XAML a dependency property of type Type in Silverlight since the markup extension {x:Type} does not exist ?
Thanks,
Depending on your requirement there may be a range of different approaches to take. The following is very general solution.
Create a value converter which converts a string to a 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
}
Place an instance of this converter in resource dictionary of which destination object has visibility, say the App.xaml:-
<Application.Resources>
<local:StringToTypeConverter x:Key="STT" />
</Application.Resources>
Now in your Xaml you can assign a value to a property like this:-
<TextBox Text="{Binding Source='System.Int32,mscorlib', Converter={StaticResource STT}}" />