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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:01:05+00:00 2026-06-11T01:01:05+00:00

I am trying to understand Binding so I have come up with a very

  • 0

I am trying to understand Binding so I have come up with a very simple program to try and test it.

I have the following element in my MainWindow:

<ComboBox Name="comboBox1" ItemsSource="{Binding}" />

In my Code I have the following observable collection:

public ObservableCollection<string> ComboItems = new ObservableCollection<string>();

I can successfully add items this way at any point during runtime:

comboBox1.DataContext = ComboItems;
ComboItems.Clea();
ComboItems.Add("Item");

My question is, how could I set the DataContext in XAML so that I don’t have to do it in code? Is it possible?

Thank you!

  • 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-11T01:01:06+00:00Added an answer on June 11, 2026 at 1:01 am

    Something common is:

    <Window DataContext="{Binding RelativeSource={RelativeSource Self}}">
        <ComboBox ItemsSource="{Binding ComboItems}" .../>
    

    However usually you want to inject another object instance as DataContext, have a look at the MVVM pattern for example. Properties in WPF are inherited, so the ComboBox has the DataContext of the Window, it can be overwritten at any level though.

    Note: For the Binding to work ComboItems needs to be a public property, not a field.

    Resources of interest:

    • Data Binding Overview
    • Data Templating Overview
    • Depedency Properties Overview
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand Binding so I have come up with a very
I am trying to make a (very) simple Data Binding test, but it doesn't
I'm trying to better understand Silverlights binding mechanism and so have created a simple
I'm trying to understand WPF binding. As simple as it gets: I have a
I am trying to understand event binding in jQuery. I have written a simple
I have a simple jsfiddle where I'm trying to better understand value binding. I
I am still very new and trying my first serious data binding. I have
I am trying understand ViewModels deeper and I have read many articles and blogs
Trying to understand this binding process of the WPF. See the code at the
ASP.NET MVC Model Binding is still new to me and I'm trying to understand

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.