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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:45:26+00:00 2026-06-02T01:45:26+00:00

Hello I am trying to bind a ItemsSource to a ObservableCollection. It seems the

  • 0

Hello I am trying to bind a ItemsSource to a ObservableCollection. It seems the ObservableCollection is not seen by the IntelliSense event if the ObservableCollection is public.

Do I have the declare something in XAML to make it visible ? Like in Window.Ressources.

My XAML code

<Window x:Class="ItemsContainer.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">

    <StackPanel Orientation="Horizontal">
        <ListBox ItemsSource="{Binding StringList}" />
    </StackPanel> </Window>

My C# code

using System.Collections.ObjectModel;
using System.Windows;

namespace ItemsContainer
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {

        private ObservableCollection<string> stringList = new ObservableCollection<string>();

        public ObservableCollection<string> StringList
        {
            get
            {
                return this.stringList;
            }
            set
            {
                this.stringList = value;
            }
        }

        public MainWindow()
        {
            InitializeComponent();
            this.stringList.Add("One");
            this.stringList.Add("Two");
            this.stringList.Add("Three");
            this.stringList.Add("Four");
            this.stringList.Add("Five");
            this.stringList.Add("Six");
        }
    }
}

To the best of my knowledge that binding should bind to the property StringList of the current
DataContext, which is MainWindow.

Thanks for any pointer.

Edit:

This worked for me in XAML

<Window x:Class="ItemsContainer.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">

    <StackPanel Orientation="Horizontal">
        <ListBox ItemsSource="{Binding RelativeSource={RelativeSource AncestorType=Window},Path=StringList}" />
    </StackPanel>
</Window>
  • 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-06-02T01:45:28+00:00Added an answer on June 2, 2026 at 1:45 am

    The DataContext does not default to the MainWindow, you’d have to explicitly set that. Like so:

    public MainWindow() {
        InitializeComponent();
        this.stringList.Add("One");
        this.stringList.Add("Two");
        this.stringList.Add("Three");
        this.stringList.Add("Four");
        this.stringList.Add("Five");
        this.stringList.Add("Six");
        this.DataContext = this;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I am trying to bind my work space and I have been doing
Hello I'm trying something .. I was reading Jquery traversing documentations some forums, this
Hello i'm trying to implement an AsynController, here is my code: [NoCache] public class
Hello I'm trying to learn ruby blocks. But I have a trouble to get
Jython 2.5 I'm trying to bind a method to the focusGained event of a
hello im trying to make something like github treeslider im new to javascript.. but
Hello I'm trying to save string into SQLite database, but nothing happens. I have
Hello Stackoverflow users, I have a question regarding an JQ UI widget im trying
Hello my fellow ColdFusion developers! I'm trying to learn node.js, and I have a
I'm trying to create something like a MDI tabbed Interface so I have a

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.