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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:35:04+00:00 2026-05-12T16:35:04+00:00

I have a TDI, bound to an observable collection of workspaces (all based on

  • 0

I have a TDI, bound to an observable collection of workspaces (all based on Josh Smith’s MVVM Demo). On one tab, there is a user control, also bound to an observable collection. If I switch tabs, the user control always jumps back to the 1st item.

I’m kinda desperate. I searched since 5 hours now but just I can’t figure out why it does this or where to search.

I simplified the whole thing as far as I could and uploaded it to: http://mad-scientists.co.uk/share/TestCandiMan.zip (about 1,5MB)

Your help is greatly appreciated!

I use C# Express 2008.

  • 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-12T16:35:05+00:00Added an answer on May 12, 2026 at 4:35 pm

    The problem here is that the TabControl instantiaties a new DataTemplate for its content each time you select another tab item, so your view is recreated with everything sets to default. You must implement a mechanism to have an unique view for a given view model. Without MVVM you would just add a View property to the ViewModel but that’s largely defeating the purpose of MVVM here.

    Edit following your comments: what I meant is that each time you’re switching tab, the TabControl will display its content using a new visual tree from the DataTemplate.

    Let’s take an example:

    1. You select the tab #1, its content is a CustomerViewModel. A new visual tree (from your NewCustomerView) is created from the DataTemplate and shown on the TabControl. The caret is in the first textbox, the tab has its first index selected, etc.

    2. You select tab #2. Content from tab #1 is not anymore in the visual tree and is discarded. The content from tab #2 will follow the same process as 1. to build a tree.

    3. You select tab #1 again. Content from tab #2 is not anymore in the visual tree and is discarded. And here, the same mechanism activates again. A new visual tree is built from the DataTemplate, with everything at its default. Woops! But that’s normal since WPF’s ContentPresenter won’t keep a content’s tree in memory for every possible object that has been its content once.

    => The theorical solution, build yourself your visual. For example, in a totally imperfect world, creates an unique NewCustomerView in your CustomViewModel, and exposes it via a property, ley’s say View. The new DataTemplate that you’ll use will be :

    <DataTemplate DataType="{x:Type CustomerViewModel}">
        <ContentPresenter Content="{Binding View}" />
    </DataTemplate>
    

    And voila, when a visual tree is created from the template, the presenter will be a totally new one, but the View is unique and won’t be recreated so the caret will be at the same place the user left it, same thing for the tabs.

    But, like I said before, this don’t go well at all with MVVM philosophy. Try to build a static class that is able to return an unique View for a given ViewModel, or something like that.

    Another solution will be to add to your ViewModel things like SelectedTabIndex and bind them, CurrentFocusPosition and such but that’s totally view-related to me.

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

Sidebar

Related Questions

Inside table td i have control(s). there must be one control inside td but
Hi I have table in one td i have text and in another td
Have deployed numerous report parts which reference the same view however one of them
Have a SQL problem, adding this model all works correctly, the problem is in
Have a simple form that has a PictureBox in one location. I want to
Have two tables say ABC and XYZ and contain one column which data will
I have a table. I one of the td I have some longer text.
I have a table structure looking something like this. One outer table and in
I have the following collection in an XML document: <events> <event> <type>Downloaded</type> <result>Sucess</result> </event>
Have one Doubt In MVC Architecture we can able to pass data from Controller

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.