Question

I would like to create my ObjectDataProvider in my C# code behind rather than my XAML.

I was wondering how to change this XAML into equivalent C#. The XAML was generated by Microsoft Expression Blend 2, so the d: namespace can be ignored safely.

<ObjectDataProvider x:Key="FooSourceDS" ObjectType="{x:Type myNS:FooSource}" d:IsDataSource="True"/>

myNS is a namespace referencing my CLR object.

I'm getting hung up on specifying the ObjectType in C#:

ObjectDataProvider FooSourceDS = new ObjectDataProvider();
FooSourceDS.ObjectType = myNamespace.FooSource;

The Intellisence is correctly identifying FooSource as a 'type' which is what ObjectType is looking for isn't it?

Was it helpful?

Solution

Is this what you need?

FooSourceDS.ObjectType = typeof(myNamespace.FooSource)

OTHER TIPS

The answer to your question is what @Bryan wrote, But cross check whether you want an ObjectDataProvider at the code lever or not. ObjectDataProvider is just a XAML way of instantiating a particular Class for Binding. But if you wish to code in C# then you dont really require ObjectDataProvider. Just create an Instance of the FooSource and use it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top