object ConvertToType (DependencyProperty dp, object value)
{
if (Binding.Converter != null) {
value = Binding.Converter.Convert (value,
Property.PropertyType,
Binding.ConverterParameter,
GetConverterCulture ());
}
try {
if (value == null) {
value = Binding.TargetNullValue;
} else if (value == DependencyProperty.UnsetValue) {
value = Binding.FallbackValue;
} else {
string format = Binding.StringFormat;
if (!string.IsNullOrEmpty (format)) {
if (!format.Contains ("{0"))
format = "{0:" + format + "}";
value = string.Format (GetConverterCulture (), format, value);
}
}
return MoonlightTypeConverter.ConvertObject (dp, value, Target.GetType (), true);
} catch {
return MoonlightTypeConverter.ConvertObject (dp, Binding.FallbackValue, Target.GetType (), true);
}
}