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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:23:29+00:00 2026-05-20T07:23:29+00:00

I am new to WPF and I am trying to get databinding to work

  • 0

I am new to WPF and I am trying to get databinding to work with a combo box. I have a class I created called FolderList that basically wraps around a FileSystemWatcher instance. It has a property called Folders that returns a dictionary of the folder names and their full paths.

Then for the class for my WPF window it has contains an instance of FolderList called FolderWatcher that is configured in the constructor. I would like to databind a combobox to the dictionary in that specific instance of FolderList.

I’ve found examples where there are static instances of data objects or where they are created through XAML but I can’t figure out how to bind to a specific instance.

I am not picking if this is done in XAML or C#. I’ve basically gotten this far with the ObjectDataProvider.

<Window.Resources>
<ObjectDataProvider x:Key="ProjectNames"
        ObjectType="{x:Type local:FolderList}"
    />
</Window.Resources>

And here is the combo box I want to data bind. This doesn’t produce any errors but it also isn’t populated. I know enough to know I am missing something major in the ObjectDataProvider but I just don’t know what it is.

<ComboBox Name="ProjectCombo" MinWidth="100" ItemsSource="{Binding Source={StaticResource ProjectNames}, Path=Folders}" />
  • 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-20T07:23:30+00:00Added an answer on May 20, 2026 at 7:23 am

    You don’t need a the ObjectDataProvider here. Just set ItemsSource of your ComboBox directly in the Window‘s contructor, where you initialize your instance of FolderList:

    public MyWindow()
    {
       InitializeComponent();
    
       FolderWatcher = new FolderList(...);
    
       ProjectCombo.ItemsSource = FolderWatcher.Folders;
    }
    

    Another option would be to set the instance of FolderList as DataContext of your window and then use binding to set ItemsSource of theComboBox`:

    public MyWindow()
    {
        InitializeComponent();
    
        FolderWatcher = new FolderList(...);
    
        DataContext = FolderWatcher;
    

    }

    <ComboBox Name="ProjectCombo" MinWidth="100" ItemsSource="{Binding Folders}" />
    

    I suggest you look into MVVM pattern. If you designed your application according to that pattern, you would have a View Model instance as DataContext of your view and that View Model would expose a property you could bind to.

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

Sidebar

Related Questions

I'm trying to get databinding set up in WPF. I've got the class person,
I'm new to WPF and trying to figure out all this databinding stuff. When
I'm new to WPF and I'm trying to figure out how to get the
I have been trying to learn and take advantage of WPF and databinding. I
I'm trying to get a legacy MFC application and a new WPF usercontrol to
I am trying to use WPF databinding features to get a TreeView to display
new to WPF and MVVM, and trying to get my head around the normal
I am very new in WPF. I have been trying to do the following:
I'm having an issue using a new WPF app that is trying to display
I'm completely new to databinding in WPF, and I'm trying to bind an object

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.