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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:37:48+00:00 2026-05-26T13:37:48+00:00

I have a list of tab items that have views dynamically added to them.

  • 0

I have a list of tab items that have views dynamically added to them. Every time a user adds a view, a new tab item is created. I’m now trying to bind a menu to a tabcontrol’s items so that a user can select from a menu which view is currently the active view.

My menu is bound as such:

<Menu Background="Transparent">
    <MenuItem Style="{StaticResource TabMenuButtonStyle}" ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TabControl}}, Path=Items}" ItemContainerStyle="{StaticResource TabMenuItem}"></MenuItem>
</Menu>

This works fine and has the desired effect (each menu item is a listing of all the open tabs).

I have the following style that binds menu items to the IsSelected property of the tab items:

<Setter Property="IsChecked" Value="{Binding Path=IsSelected, Mode=TwoWay}" />

My problem is, this binding doesn’t work. The binding error message is stating that it can’t find the IsSelected property on the view object. I don’t want it to use the specfic view, rather, I want it to look at the tab item that the view is currently bound to.

I’ve tried the following, but still get a binding error:

<Setter Property="IsChecked" Value="{Binding Path=IsSelected, Mode=TwoWay, RelativeSource={RelativeSource AncestorType=TabItem}}}" />

Which states that it can’t find an ancestor of type TabItem for each menu item (which makes sense as the menu item’s ancestors are not what it is bound to.)

Is there any way I can get access to the parent of the item that is coming in as a binding so I can bind to its properties?

Update:

Per Yadyn’s advice, I decided to create a value converter and return tab items.

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
        ItemCollection ic = (ItemCollection)value;
        List<TabItem> tabItems = new List<TabItem>();
        foreach (var obj in ic) {
            tabItems.Add((TabItem)obj);
        }
        return tabItems;
    }

This makes binding IsSelected to IsChecked work for static items (TabControls that have their tab items already created), but for the dynamically added views, the Convert method never gets called. It’s like the TabControl is not sending out an update to binders of its items that something has changed. Here is how the MenuItem is wired up now:

<MenuItem Style="{StaticResource TabMenuButtonStyle}" ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TabControl}}, Path=Items, Mode=OneWay, NotifyOnSourceUpdated=True,  Converter={StaticResource TabControlItemConverter}}" ItemContainerStyle="{StaticResource TabMenuItem}"></MenuItem>
  • 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-26T13:37:49+00:00Added an answer on May 26, 2026 at 1:37 pm

    TabControl.Items will get you back the views, since that is what you’ve bound to your TabControl to have dynamic tab views.

    Unfortunately, there isn’t a property you can bind to on the TabControl directly that will get you a collection of the TabItems. These are actually the ItemContainers for each item in the Items bound collection.

    What you might do is create a converter or something. You can try using myTabControl.ItemContainerGenerator.ContainerFromItem and pass in the view object to get back the actual TabItem that wraps it. Then your IsSelected binding will work.

    You might consider binding directly to the TabControl itself instead of the Items property. Then the converter can easily do the above call to ContainerFromItem. You’ll then have to return a List<TabItems> from the converter by enumerating the Items property yourself (calling ContainerFromItem for each).

    Anyway, hopefully this gets you on the right track!

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

Sidebar

Related Questions

i have list of rows that user select and i want to delete them,
I have a list that has 5 items in, the first one (on load)
In my Tab Bar application, I want the user to have a list of
I have a custom control that is derived from ListView . This list view
I have created a list view within a tab with a list of teams
I have a UL list in a ASPX page: <ul id=tabs> <li id=tab1><a href=ztab1.htm>Tab
I have a WPF Menu and a Tab control. I would like the list
I have a TabActivity with a tab, which shows a list. I'd like to
So I have one activity with a listview in it that is dynamically updated
In a MVVM WPF application, I have a master-detail View that is used to

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.