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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:54:22+00:00 2026-06-01T10:54:22+00:00

I create a TabControl in C# code. I bind its ItemsSource to a collection

  • 0

I create a TabControl in C# code. I bind its ItemsSource to a collection and set margin.
For some reason, to set its DisplayMemberPath wont work.

_tabControl = new TabControl();
_tabControl.Margin = new Thickness(5);
_tabControl.DisplayMemberPath = "Header";
_tabControl.SetBinding(ItemsControl.ItemsSourceProperty, itemsSourceBinding);

Each item in the collection have a property called “Header”.

Why does that not work?

André

EDIT:
Here is all relevant code:

public partial class VariationGroupPreviewOptionsView
{
    public string Header { get; set; }

    public VariationGroupPreviewOptionsView()
    {
        InitializeComponent();
        DataContext = new VariationGroupPreviewOptionsViewModel();
    }
}

private void OptionsCommandExecute()
{
    var dlg = new OptionsDialog();
    dlg.ItemsSource = new List<ContentControl>() {new VariationGroupPreviewOptionsView(){Header = "Test"}};
    dlg.ShowDialog();
}

public class OptionsDialog : Dialog
{

    public static readonly DependencyProperty ItemsSourceProperty =
        DependencyProperty.Register("ItemsSource", typeof (IEnumerable), typeof (OptionsDialog), new PropertyMetadata(default(IEnumerable)));

    public IEnumerable ItemsSource
    {
        get { return (IEnumerable) GetValue(ItemsSourceProperty); }
        set { SetValue(ItemsSourceProperty, value); }
    }

    private readonly TabControl _tabControl;


    public OptionsDialog()
    {
        DataContext = this;
        var itemsSourceBinding = new Binding();
        itemsSourceBinding.Path = new PropertyPath("ItemsSource");

        _tabControl = new TabControl();
        _tabControl.Margin = new Thickness(5);
        _tabControl.DisplayMemberPath = "Header";
        _tabControl.SetBinding(ItemsControl.ItemsSourceProperty, itemsSourceBinding);

        var recRectangle = new Rectangle();
        recRectangle.Margin = new Thickness(5);
        recRectangle.Effect = (Effect)FindResource("MainDropShadowEffect");
        recRectangle.Fill = (Brush)FindResource("PanelBackgroundBrush");

        var grdGrid = new Grid();
        grdGrid.Children.Add(recRectangle);
        grdGrid.Children.Add(_tabControl);

        DialogContent = grdGrid;
    }
}
  • 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-01T10:54:23+00:00Added an answer on June 1, 2026 at 10:54 am

    If you clean up and simplify your code, you’ll see that setting DisplayMemberPath works exactly as you want it to:

    XAML:

    <TabControl ItemsSource="{Binding}" DisplayMemberPath="Header"/>
    

    Code:

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
    
            this.DataContext = new List<TabItemModel>
            {
                new TabItemModel
                {
                    Header = "First"
                },
                new TabItemModel
                {
                    Header = "Second"
                },
            };
        }
    }
    
    public class TabItemModel
    {
        public string Header
        {
            get;
            set;
        }
    }
    

    Result:

    enter image description here

    So, the problem is not that TabControl.DisplayMemberPath doesn’t work – it’s somewhere else in your code. Simplify until you find where.

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

Sidebar

Related Questions

I want to create dynamic tabPages in TabControl. In each tabPage I create dataGridView
I've created this simple demo because I'm having some trouble making auto-sizing work in
I create a basic TemplatedControl via Visual Studio. I then inherit TabControl instead of
so i've been searching the net, and I've found some code to add controls
i need to create types of Tabitems to my tabcontrol. each tab will have
I have create a tabcontrol in Silverlight 4 with four tabs, is possible open
How to create trapezoid tabs in WPF tab control? I'd like to create non
I want to create a UI that uses a tab control to display multiple
I have to develop a customized tab control and decided to create it with
Create Proc CrearNuevoAnuncio @Titulo varchar(250), @Precio int, @Descripcion varchar(250), @IDCategoria int, @IDImagen int, @Login

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.