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

The Archive Base Latest Questions

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

I am working on my first ‘production’ WPF app, and I’m encountering an issue.

  • 0

I am working on my first ‘production’ WPF app, and I’m encountering an issue.
I have some code that is similar to the example below. The problem I am having is that I cannot get the ComboBox to populate. I’m assuming it is because the Grid‘s ItemsSource is ‘blocking’ the ComboBoxfrom being able to see the Tasks collection on the ViewModel, but I am only guessing. Everything else is databinding correctly.

I scoured SO and found this question; which sounds exactly like what I am trying to do, but it did not work for me.

Any idea why I can’t get the ComboBox to populate?

Model:

public class Activity{
  public int Id { get; set; }
  public string Title { get; set; }
  public Task Task { get; set; }
}

public class Task{
  public int Id { get; set; }
  public string Title { get; set; }
}

ViewModel:

public ApprovalViewModel{
  public ObservableCollection<Activity> Activities { /* ... property logic */ }
  public ObservableCollection<Task> Tasks { /* ... property logic */ }
}

View:

<DataGrid ItemsSource="{Binding Activities}" AutoGenerateColumns="False">
    <DataGrid.Resources>
        <DataTemplate x:Key="displayTemplate">
            <TextBlock Text="{Binding Task.Title}"/>
        </DataTemplate>
        <DataTemplate x:Key="editTemplate">
            <ComboBox ItemsSource="{Binding Tasks}" <!--I think the problem is here-->
              SelectedValue="{Binding Task}"
              DisplayMemberPath="Title"/>
        </DataTemplate>
    </DataGrid.Resources>
    <DataGrid.Columns>
        <DataGridComboBoxColumn DisplayMemberPath="Title"/>
        <DataGridTextColumn Binding="{Binding User}" Header="User"/>
        <DataGridTextColumn Binding="{Binding Task.Project.Title}" Header="Project"/>
        <DataGridTemplateColumn 
            Header="Task" 
            CellTemplate="{StaticResource displayTemplate}" 
            CellEditingTemplate="{StaticResource editTemplate}"/>
        <DataGridTextColumn Binding="{Binding Description}" Header="Description"/>
    </DataGrid.Columns>
</DataGrid>

Edit: the correct ComboBox code is here:

<ComboBox 
  ItemsSource="{Binding Path=DataContext.Tasks, 
                        RelativeSource={RelativeSource FindAncestor, 
                                        AncestorType={x:Type UserControl}}}"
  SelectedValue="{Binding Task.Title}"
  SelectedValuePath="Title"
  DisplayMemberPath="Title"/>
  • 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-20T05:31:30+00:00Added an answer on May 20, 2026 at 5:31 am

    You are correct in where the problem lies, that binding is relative to the Activity. So it is looking for Activity.Tasks.

    The post you linked to has the right approach, you just need to tweak it for your situation.

    ItemsSource="{Binding Path=DataContext.Tasks, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" 
    

    This will go back up the Visual tree looking for a Window, which has a DataContext.Tasks property.

    Is your code example inside a window? If not you will need to change the {x:Type } and secondly is the DataContext set on this object? If not you will need to set it to your ViewModel.

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

Sidebar

Related Questions

I am new to wpf and i am working on first application i have
I am working on my first iOS app, and have run in the first
I have a problem with ui dialog close function. My code working first click
First to tell you my issue: I have written a program that based on
I have pretty much finished my first working Symbian application, but in my hastened
For some weird reason, the codes below are first working, then website is redirecting
Working on my first Android app here. I've searched and tried everything I can
I working on my first ASP.net MVC project and and i got some problems
I'm working on my first application that will use entity framework. I've got a
I'm working for the first time with Forms Authentication, I'm using an example from

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.