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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:03:08+00:00 2026-05-20T15:03:08+00:00

I am having trouble with declaratively setting the ItemsSource of a ListBox contained within

  • 0

I am having trouble with declaratively setting the ItemsSource of a ListBox contained within a PivotItem in a simple Windows Phone 7 page. I can successfully set the ItemsSource in code behind.

Here is a snippet of the class that contains the ObservableCollection that I want to bind to:

sealed class Database : INotifyPropertyChanged
{
    //Declare Instance
    private static readonly Database instance = new Database();

    //Private Constructor
    private Database() { }

    //The entry point into this Database
    public static Database Instance
    {
        get
        {
            return instance;
        }
    }

    #region Collections corresponding with database tables

    public ObservableCollection<Category> Categories { get; set; }
    public ObservableCollection<CategoryType> CategoryTypes { get; set; }

And here is a sample of my XAML:

<ListBox x:Name="CategoriesListBox" Margin="0,0,-12,0" ItemsSource="{Binding Categories}" DisplayMemberPath="Name" />

In my page I have tried setting the data context as follows:

this.DataContext = Database.Instance;

However the binding does not work unless I explicitly set the ItemsSource in code as follows:

CategoriesListBox.ItemsSource = Database.Instance.Categories;

I know that I should be able to do this all declaratively, however I have tried many different ways of setting the ItemsSource declaratively (in addition to what I have detailed above) and none work.

Can someone help me out?

Further info: The output windows at runtime shows the following: System.Windows.Data Error: Cannot get ‘Categories’ value (type ‘System.Collections.ObjectModel.ObservableCollection`1[BTT.PinPointTime.Entities.Category]’) from ‘BTT.PinPointTime.WinPhone.Database’ (type ‘BTT.PinPointTime.WinPhone.Database’). BindingExpression: Path=’Categories’ DataItem=’BTT.PinPointTime.WinPhone.Database’ (HashCode=99825759); target element is ‘System.Windows.Controls.ListBox’ (Name=’CategoriesListBox’); target property is ‘ItemsSource’ (type ‘System.Collections.IEnumerable’).. System.MethodAccessException: Attempt to access the method failed: BTT.PinPointTime.WinPhone.Database.get_Categories()
at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr

  • 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-20T15:03:09+00:00Added an answer on May 20, 2026 at 3:03 pm

    I found out that the problem was related to the access level of my Database class. When I changed it from “sealed” to “public sealed” the databinding worked.

    public sealed class Database : INotifyPropertyChanged
    {
        //Declare Instance
        private static readonly Database instance = new Database();
    
        //Private Constructor
        private Database() 
        {
            //Categories = new ObservableCollection<Category>();
        }
    
       //more code here....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having trouble creating a simple mixin that i plan to use on
Having trouble with pattern and replacement. How can I make the replacement echo a
Having trouble with a function hitting the page as soon as possible, so i
Having trouble figuring out how to impersonate another user while using aspnet_personalization with Windows
Having trouble installing play! on windows. Following the installation guide on: http://www.playframework.org/documentation/1.2.4/install After installing
Having trouble with this..I'm sure I'm missing something simple but I simply want the
having trouble coming up with search parameters for this issue, so I can't find
I having trouble with a simple question : How to have some disabled field
Having trouble extending the left and right divs to the bottom of the page,
Having trouble setting the value of a declared variable in MySQL. If I run

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.