Searched around and could not find a response for this. Does anybody know of a way to call a static method from a static class within XAML. I know that it is possible to call a static method from a regular class using ObjectDataProvider by doing something like:
<ObjectDataProvider x:Key="mthd" ObjectType="{x:Type l:MyClass}" MethodName="MyStaticMethod">
<ObjectDataProvider.MethodParameters>
<sys:String>Test</sys:String>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
I have tried this with the static class and it fails. Since the static class cannot be instantiated with the exception of “Object reference not set to an instance of an object”.
Can something similar to this be done for static classes in .Net 4.0?
Thanks in advance!
Creating something like an
ObjectDataProvideis really simple, you just need to use a bit of reflection. Get the class type via aTypeproperty right from XAML along with the method name and parameters, then useGetMethodwith the rightBindingFlagsand invoke it with the passed parameters.