Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 976013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:40:44+00:00 2026-05-16T03:40:44+00:00

I have an ObjectDataProvider in my XAML that references a method in my Window

  • 0

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 ObjectDataProviders 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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T03:40:44+00:00Added an answer on May 16, 2026 at 3:40 am

    The root of the problem here is that ObjectDataProvider always creates a new instance of whatever object it’s created for. So yes, it will create an instance of the NewForm class, whose constructor will instantiate another ObjectDataProvider that creates an instance of the NewForm class, and then it’s turtles all the way down.

    But the thing is, ObjectDataProvider is really just a way to declare create objects and call methods on them in XAML, so that you don’t have to do it in code-behind. Since you’re already creating the object in code-behind, avoiding code-behind isn’t benefiting you. So just have the method that creates the object also add it to the window’s resource dictionary:

    // this method no longer needs to return anything, so you can change its signature
    private void GetTeamName()
    {
        // code that creates the object goes here.
        // and now, instead of "return myObject", do this:
        Resources.Add("getTeamOName");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF app that is currently driven completely from XAML. All fields,
I have a XAML Window that has a set of strings that are bound
I have the following XAML inside a user control: <UserControl.Resources> <ObjectDataProvider x:Key=DataSources ObjectInstance={x:Static data:Sql.SqlDataSourceEnumerator.Instance}
I have XAML File as below: <Window x:Class=ComboBoxCheck.Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:check=clr-namespace:ComboBoxCheck Title=Window1 Height=300 Width=320>
Have you managed to get Aptana Studio debugging to work? I tried following this,
Have following listener for keyboard ArrowDown event(it's key code is 40 ): window.onload =
I have the following definition in my xaml file to bind a combobox to
I have a list saved in the ObjectInstance of the ObjectDataProvider class. When calling
I have a ComboBox whose ItemsSource is bound to an ObjectDataProvider that has its
I have a chart control in XAML, and datapoints that are bind to the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.