I looked a bit using the .NET reflector, and there seems to be no official way to get the default converter.
What you need is to call a method
internal IValueConverter GetDefaultValueConverter(Type sourceType, Type targetType, bool targetToSource);
in the class MS.Internal.Data.DataBindEngine .
You will get the current DataBindEngine to start the stream with a static internal property.
internal static DataBindEngine CurrentDataBindEngine
Always in the DataBindEngine class.
The problem is that the class is inner!
I also looked to see if there is anything public that uses this method, but in fact this method and default conversion classes (there are more than one!) Are used only inside the internal data binding classes, so I'm sorry in no way.
You can use reflection to access internal members, but it will be a very bad dirty hack! To do this, access the static property DataBindEngine.CurrentDataBindEngine, then access the GetDefaultValueConverter method, always with reflection. Wrap a static function with the [Deprecated] attribute :)
Probably a cleaner way is to simply use manual conversion by default.
You can simply try to understand why this gives you an error or write code that can handle special cases. Their code is quite complex and interconnected, I would not suggest copying their code.
Once WPF makes me angry, many things related to data binding are hidden, internal or insufficiently generalized, and this is a very bad design that I do not understand.
The old TypeConverter was once enough. It depends on what you have to do.
public static object MyConvert(object value, Type t) { TypeConverter tc = TypeDescriptor.GetConverter(t); return tc.ConvertFrom(value); }
You can also try the static Convert.ChangeType method, which works with IConvertible .
I assume that the problem is not in converting your object, but in converting it to the value used by the dependency property (or vice versa). To do this, there is a public class XamlValueConverter , also used internally by default value converters. However, it will be difficult, therefore ... not a simple solution to your problem.
As Merlin goes on to say, I'm starting to believe that reflection can be a more appropriate way.