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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:05:02+00:00 2026-06-01T23:05:02+00:00

Well, I have been scratching my head for some time now. But failed to

  • 0

Well, I have been scratching my head for some time now. But failed to find solution to my problem. What I have is a MainViewModel with and ObservableCollection TabItems. The MainViewModel is set as DataContext for the MainView (User Control) which in turn hosts the TabControl. The tabcontrol is bound to TabItems collection. The Content of the tabcontrol will be ReportItems User Control.

This setup is basically for report for reporting UI for SSRS. The first tab contains a list of Reports selecting which would show a few listboxes from where the user would select the Report Parameters. Not after selecting parameters, the user click a button which in turn generates a report and adds a tab to the tab control with the reporthost.

The reason I am trying to select the report from a tab and not the Main View is that there are a lot of parameters to be selected and if I add the listboxes to the MainView, the space left for the tabcontrol would be less and the user would need to scroll down to view the reports.

I am not sure if my design is flawed but I wanted to figure out a way to add the new ReportItemViewModel to be added to the TabItem collection. That means allowing a child tab to add a sibling by sending a ReportItemViewModel object to MainViewModel and add to the colection.

I thought of using a static Collection to do so but that would not call my OnPropertyChange method. Also, having a static method in the MainViewModel does not help as it would not be able to add the object to the collection since the collection is not static.

I am not posting any code here since I am stuck at how to begin itself. I looked at another post here but could not figure out how to use it.

Sorry for long description, Just wanted to make the question clear.

I am open to any suggestion, also if I can get a better design. I am desperate and any help would be appreciated.

  • 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-01T23:05:04+00:00Added an answer on June 1, 2026 at 11:05 pm

    Add an ICommand to your MainViewModel for adding a new item to your ObservableCollection, and use a RelativeSource binding to find the command from within the TabItem

    So your MainViewModel would have

    ObservableCollection<IViewModel> TabItems
    IViewModel SelectedTabItem
    ICommand AddTabCommand
    

    where AddTabCommand basically does

    void AddTab(IViewModel newItem)
    {
        TabItems.Add(newItem);
        SelectedTabItem = newItem;
    }
    

    and your UI would look something along the lines of this

    <DataTemplate DataType="{x:Type local:SelectReportViewModel}">
        <Grid>
            ...
            <!-- Use the CommandParameter property to pass specified ReportItemViewModel to open -->
            <Button Command="{Binding DataContext.AddTabCommand, 
                    RelativeSource={RelativeSource AncestorType={x:Type TabControl}}}" />
            ...
        </Grid>
    </DataTemplate>
    
    <TabControl ItemsSource="{Binding TabItems}" />
    

    Another alternative is to use some kind of event system, such as MVVM Light’s Messenger or Microsoft Prism’s EventAggregator, to broadcast/subscribe to events.

    Your MainViewModel would subscribe to AddTabEvents, while your SelectReportViewModel would broadcast those events anytime a new tab should be added. I have a brief summary on my blog article about communication between ViewModels if you’re interested.

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

Sidebar

Related Questions

Similar questions have been asked but cannot find a solution that works well. What
This question may well have been asked before but I didn't find anything whilst
well i have most probably an extremly stupid problem but could not figure it
Well I have been able to figure this out but what I want to
I have a very annoying problem that has left me scratching me head when
Well I have been reading quite a lot sources but they differ in definiton:
Ok well I have been fighting with this for a while now and have
I have been using media queries for the first time, and things going well,
Well I have been through many sites teaching on how to solve it, but
The differences between StringBuilder and StringBuffer in Java are well documented and have been

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.