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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:25:35+00:00 2026-05-22T01:25:35+00:00

My goal is to add different Controls/UserControls in a WPF ListView. The Controls can

  • 0

My goal is to add different Controls/UserControls in a WPF ListView. The Controls can be of any types. Here is an example of what it would look like with 3 different Controls/UserControls:

enter image description here

WHAT WORKS

This would work if I use the following XAML and code:

<ListView Name="ControlsListView">
    <ListView.View>
        <GridView>
            <GridViewColumn Header="Control"/>
        </GridView>
    </ListView.View>
</ListView>

Here is the code:

ObservableCollection<Control> Controls { get; set; }
//...
ControlsListView.ItemsSource = Controls;
//...
Controls.Add(new ThresholdControl());
Controls.Add(new CheckBox());
Controls.Add(new Button()
                     {
                        Content = "Test"
                     });

WHAT DOESN’T WORK

My problem is when I want to add a level of indirection in the ObservableCollection. Instead of using directly a collection of Control, I would like to have a collection of MyItem. MyItem would itself contain the Control to display. Something like this:

class MyItem
{
    public Control MyControl { get; set; }
}

ObservableCollection<MyItem> Controls { get; set; }

And I would bind my ListView like this:

<GridViewColumn Header="Control" DisplayMemberBinding="{Binding MyControl}"/>

When displaying a string, this will work ok, but for displaying a Control, this won’t work. In fact, in my example, it would display the string representing the class of the Control inserted in the list instead of the Control itself.

What do I need to do to bind to the Controls in my list? DisplayMemberBinding doesn’t seem to be the good choice here.

Thanks!

  • 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-22T01:25:36+00:00Added an answer on May 22, 2026 at 1:25 am

    You want to use the CellTemplate property instead of DisplayMemberBinding. You can then have your CellTemplate display the control you want. I think the code would look something like this:

    <ListView Name="ControlsListView">
        <ListView.View>
            <GridView>
                <GridViewColumn Header="Control">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <ContentControl Content={Binding MyControl} />
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
            </GridView>
        </ListView.View>
    </ListView>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the task: I would like my JavaScript code from different files to
Goal I am building an Eclipse plugin targeting the 3.7 environment and would like
I have about 30 different flagged enums that I would like to put into
The goal: I'm trying to achieve something like this in WPF: (source: wordpress.org )
Goal: Right clicking in the listview and choose different option. Problem: There are two
Goal: Display different context menu if right clicking a row from the listview or
The goal is to be able to add a PDF file to the assets
Goal : I wants when I drag image it become fade so we can
GOAL : To customize the background view of cell. Here is what I am
Goal: to create a percentage column based off the values of calculated columns. Here's

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.