A really tough one this. I had to think about it but I don't you are going to like the answer (no its not 42).
The strict answer is no there isn't. However there is a horrible one-shot solution which frankly I don't recommend but if its absolutely unavoidable might be useful. First you need a value converter:-
public class ConvertibleValueConverter : IValueConverter
{
public bool Converted { get; private set; }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
Converted = true;
return ((IConvertible)value).ToType(targetType, culture);
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return ((IConvertible)value).ToType(targetType, culture); ;
}
}
Now you can modify your source code as follows:-
Binding binding = new Binding(SourceName);
binding.Mode = BindingMode.TwoWay;
binding.Converter = new ConvertibleValueConverter();
BindingExpressionBase beb = SetBinding(SourceDependencyProperty, binding);
if (!((ConvertibleValueConverter)binding.Converter).Converted)
{
// Path SourceName was not found.
}
This code assumes that an appropriate DataContext is already in place. The Converter only handles the typical conversions between the basic system types that implement IConvertible (String, Int, Double, DateTime etc). It works because Convert
will only get called if the property path is found.