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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:05:50+00:00 2026-05-31T14:05:50+00:00

Okay, I got this Tabcontrol containing a ListBox. Now my problem it that I

  • 0

Okay, I got this Tabcontrol containing a ListBox. Now my problem it that I would like to bind <TextBox x:Name="DetailTextBox" Text="{Binding Detail}"/> to the selectedItem in the listbox and show the Detail property value.
Note that the TextBox is not part of the TabControl, but is in another Column.

I can’t quite figure out, how to handle binding, when there a multiple ListBox’es, one in each TabControl Item.

My classes

public class TabViewModel
{
    public string Name { get; set; }
    public ObservableCollection<TabItemViewModel> Collection { get; set; }
}

public class TabItemViewModel
{
    public string Title { get; set; }
    public string Detail { get; set; }
}

public MainWindow()

 var tabViewModels = new ObservableCollection<TabViewModel>();
            tabViewModels.Add(new TabViewModel{Name = "Tab 1", Collection = new ObservableCollection<TabItemViewModel>{new TabItemViewModel{Detail = "Detail 1.1", Title = "Title 1.1"}, new TabItemViewModel{Detail = "Detail 2.2", Title = "Title 2.2"}}});
            tabViewModels.Add(new TabViewModel { Name = "Tab 2", Collection = new ObservableCollection<TabItemViewModel> { new TabItemViewModel { Detail = "Detail 2.1", Title = "Title 2.1" }, new TabItemViewModel { Detail = "Detail 2.2", Title = "Title 2.2" } } });
            tabViewModels.Add(new TabViewModel { Name = "Tab 3", Collection = new ObservableCollection<TabItemViewModel> { new TabItemViewModel { Detail = "Detail 3.1", Title = "Title 3.1" }, new TabItemViewModel { Detail = "Detail 3.2", Title = "Title 3.2" } } });
            DataContext = tabViewModels;

MainWindow.xaml.

<Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="50*"/>
            <ColumnDefinition Width="50*"/>
        </Grid.ColumnDefinitions>
        <TabControl ItemsSource="{Binding}" Grid.Column="0" SelectedIndex="0">
            <TabControl.ItemContainerStyle>
                <Style TargetType="{x:Type TabItem}">
                    <Setter Property="Header">
                        <Setter.Value>
                            <Binding Path="Name"/>
                        </Setter.Value>
                    </Setter>
                </Style>
            </TabControl.ItemContainerStyle>
            <TabControl.ContentTemplate>
                <DataTemplate>
                    <ListBox ItemsSource="{Binding Collection}">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <Label Content="{Binding Title}" />
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                </DataTemplate>
            </TabControl.ContentTemplate>
        </TabControl>
        <StackPanel Grid.Column="1">
            <TextBox x:Name="DetailTextBox" Text="{Binding Detail}"/>
        </StackPanel>
    </Grid>

enter image description here

EDIT

Temp Solution
Found a way to make it work, but I’m still looking for a pure Xaml solution.
Added a SelectionChange event

 <ListBox ItemsSource="{Binding Collection}" SelectionChanged="ListBox_SelectionChanged">

     private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
            {
                if (e.AddedItems.Count > 0)
                    DetailTextBox.DataContext = (TabItemViewModel) e.AddedItems[0];
            }
  • 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-31T14:05:51+00:00Added an answer on May 31, 2026 at 2:05 pm

    How about this, I was surprised myself 🙂
    Make these changes to your Xaml.

    <TabControl ItemsSource="{Binding}" 
        Grid.Column="0" SelectedIndex="0" 
        IsSynchronizedWithCurrentItem="True">
    
    <ListBox ItemsSource="{Binding Collection}" 
        IsSynchronizedWithCurrentItem="True">
    
    <TextBox x:Name="DetailTextBox" 
        Text="{Binding /Collection/Detail}"/>
    

    The ‘/’ binds to the currently selected item of a control’s CollectionView.

    So the binding above is drilling down through

    • The currently SelectedItem of the ObservableCollection set on the Data Context
    • The Collection property on that item
    • The currently SelectedItem of the Collection property (ObservableCollection)
    • The Detail property on that item.

    In order for this to work we need to specify IsSynchronizedWithCurrentItem="True" to ensure the SelectedItem remains synchronized with the current item of each collection.

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

Sidebar

Related Questions

Okay, so I've got some example xml that looks like this: <Node name=details> <Node
So, I've got this image for my app that looks like this: Now this
Okay, possibly my last flex problem :) Got this ItemRenderer <?xml version=1.0 encoding=utf-8?> <s:ItemRenderer
Okay I've got my app.config file that is containing my database settings. All works
Okay, now I've got this thing I need to do with Javascript but I
We've got a view that's defined like this CREATE VIEW aView as SELECT *
Okay, so I've got a couple of headers with links in them. Like this:
Okay, this has got to be something stupid-as-a-box-of-rocks that I'm doing wrong, but I
Okay, I got this small program which tags (as in ID3v2.4 etc.) some music
Okay, so we've got this event. Awesome, right? We've also got a timer with

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.