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 4016628
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:45:47+00:00 2026-05-20T09:45:47+00:00

I’m having issues getting my databinding working for a ListBox. I suspect it’s because

  • 0

I’m having issues getting my databinding working for a ListBox. I suspect it’s because I’m trying to databind against an interface rather than a class.

My C# code:

namespace MyNamespace
{
    interface IFoo
    {
        string Bar { get; }
    }

    class Fizz
    {
        private class Buzz : IFoo
        {
            public string Bar { get { return "something"; } }
        }

        public IEnumerable<IFoo> GetFoo()
        {
            List<Buzz> items = new List<Buzz>();
            // Populate items
            return items;
        }
    }
}

When I try to do databinding with the output from Fizz::GetFoo(), it doesn’t work. My XAML looks like:

<ListBox Name="listBox1" ItemsSource="{Binding}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel>
                 <TextBlock Text="Bar:" />
                 <TextBlock Text="{Binding Bar}" />
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

When I run it, I see the text for the first TextBlock but not the second. I see errors in the Output window similar to this:

    System.Windows.Data Error: Cannot get 'Bar' value (type 'System.String') from 'Buzz' (type 'MyNamespace.Fizz+Buzz'). BindingExpression: Path='Bar' DataItem='Buzz' (HashCode=100433959); target element is 'System.Windows.Controls.TextBlock' (Name=''); target property is 'Text' (type 'System.String').. System.MethodAccessException: Attempt to access the method failed: MyNamespace.Fizz+Buzz.get_Bar()
   at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
   at System.Reflection.RuntimePropertyInfo.InternalGetValue(PropertyInfo thisProperty, Object obj, Object[] index, StacA first chance exception of type 'System.MethodAccessException' occurred in mscorlib.dll

Am I doing something wrong or is what I’m trying to do just not possible?

  • 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-20T09:45:48+00:00Added an answer on May 20, 2026 at 9:45 am

    It looks like everything in your chain needs to be public (and your List needs to be List<IFoo> instead of List<Bar>):

    public interface IFoo
    {
        string Bar { get; }
    }
    
    public class Fizz
    {
        public class Buzz : IFoo
        {
            public string Bar { get { return "something"; } }
        }
    
        public IEnumerable<IFoo> GetFoo()
        {
            List<IFoo> items = new List<IFoo>();
            // Populate items
            return items;
        }
    }
    

    The problem you are running into has to do with reflection across assemblies. The Silverlight code is reflecting on your internal class and interface (classes and interfaces are internal unless otherwise specified). Even Buzz needs to be public because it still needs to reflect upon that class, which is private, so it fails.

    Obviously, if you were not using data binding here, the code would work fine. You would have access to IFoo even though Buzz is private. But, once you bring reflection into the mix, you have to start making things public, unfortunately.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I am trying to loop through a bunch of documents I have to put
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm making a simple page using Google Maps API 3. My first. One marker
I have some data like this: 1 2 3 4 5 9 2 6

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.