views:

912

answers:

2

I am attempting to use an ObjectDataProvider to call the GetPositition method of Mouse, but am getting this error:

System.Windows.Data Error: 34 : ObjectDataProvider: Failure trying to invoke method on type; Method='GetPosition'; Type='Mouse'; Error='No method was found with matching parameter signature.' MissingMethodException:'System.MissingMethodException: Method 'System.Windows.Input.Mouse.GetPosition' not found.

This is my code at the moment:

<ObjectDataProvider MethodName="GetPosition" ObjectType="{x:Type sys:Mouse}"  x:Key="odp">
        <ObjectDataProvider.MethodParameters>
            <x:Type TypeName="local:TestType"/>
        </ObjectDataProvider.MethodParameters>
    </ObjectDataProvider>

with a simple binding:

{Binding Source={StaticResource odp}}

Why is it reporting not finding the Method no matter what I do?

A: 

I'm guessing that it's not finding the method because you're supplying Method Parameters of the wrong type. If you look at the documentation for Mouse.GetPosition, you'll see that it takes one parameter of type IInputElement; you are providing a parameter of type Type.

Samuel Jack
A: 

While Sam is correct, the point was if the process could be done with any other type or value presented.

According to the MSDN there is no way to use this with binding, though I believe you could have a reference of some sort the complexity highly overshadows the result.

The real answer is it should not be done.

Alex