private static object GetInputBindingsCollectionOwner(IProvideValueTarget targetService)
{
var xamlContextField = targetService.GetType().GetField("_xamlContext", BindingFlags.Instance | BindingFlags.NonPublic);
if (xamlContextField == null)
{
return null;
}
var xamlContext = xamlContextField.GetValue(targetService);
var grandParentInstanceProperty = xamlContext.GetType().GetProperty("GrandParentInstance");
if (grandParentInstanceProperty == null)
{
return null;
}
var inputBindingsCollection = grandParentInstanceProperty.GetGetMethod().Invoke(xamlContext, null);
var ownerField = inputBindingsCollection.GetType().GetField("_owner", BindingFlags.Instance | BindingFlags.NonPublic);
if (ownerField == null)
{
return null;
}
var owner = ownerField.GetValue(inputBindingsCollection);
return owner;
}