I have an ObjectDataProvider
in my XAML that references a method in my Window
-deriving class. That is, I have NewForm.xaml.cs
with class NewForm
and the ObjectDataProvider
in NewForm.xaml
is referencing a method in NewForm
. Currently, with the following XAML, I get a stack overflow error because the NewForm
constructor keeps getting called over and over again:
<Window x:Class="MyNamespace.NewForm" ...>
<Window.Resources>
<ObjectDataProvider x:Key="getTeamName"
ObjectType="{x:Type local:NewForm}"
MethodName="GetTeamName">
<ObjectDataProvider.MethodParameters>
<sys:Int32>-1</sys:Int32>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</Window.Resources>
</Window>
I'm guessing it's because the ObjectType
is set to NewForm
, so it loads NewForm
to load my application, but then it has to create a new instance of NewForm
in order to call GetTeamName
, but the constructor calls InitializeComponent
which creates a new NewForm
which has to create a new NewForm
to call GetTeamName
... It actually crashes Visual Studio 2010 every time.
Anyway, what I'm asking is do I have to define methods that my XAML calls via ObjectDataProvider
s in some other class? Or can I somehow use ObjectDataProvider
with a method defined in my XAML's class? Or to call a method in my XAML's class, should I be using some other XAML besides ObjectDataProvider
? It doesn't seem like I can put my C# method in another class since it uses TryFindResource
to get an XmlDataProvider
from my XAML.