tags:

views:

59

answers:

1

I'm create project using Josh Smith THE MODEL-VIEW-VIEWMODEL (MVVM) DESIGN PATTER FOR WPF

But has one problem. Same workspace shown same operation. My VIEW contains tabcontrol. after creating 2 or more same workspace,when i changing selected index for tabcontrol from any workspace, other same workspace tabcontrol shown same result.

I'm tested on the Josh smith sample project. But same as my project. If you want to show. download Josh smith code from here and on the MainWindowViewModel.cs changing following code from

void ShowAllCustomers()
        {
            AllCustomersViewModel workspace = null;
                this.Workspaces.FirstOrDefault(vm => vm is AllCustomersViewModel)
                as AllCustomersViewModel;

            if (workspace == null)
            {
                workspace = new AllCustomersViewModel(_customerRepository);
                this.Workspaces.Add(workspace);
            }

            this.SetActiveWorkspace(workspace);
        }

To

void ShowAllCustomers()
        {
            AllCustomersViewModel workspace = null;

            workspace = new AllCustomersViewModel(_customerRepository);
            this.Workspaces.Add(workspace);            

            this.SetActiveWorkspace(workspace);
        }

Then Run Code and Open 2 or more All Customer view and changing List view Column order. All opened all customer view shown same result

How to fix this problem

+2  A: 

If I might quote Sacha Barber the creator of Cinch at http://www.codeproject.com/KB/WPF/CinchV2_3.aspx see the section "WorkSpaces : Special Notes" From the sound of it you might be having the same problem, but I'm learning as well so I could be wrong.

"Now all of this is grand, but unfortunately WPF throws some weirdness in our path, in the form of the TabControl. Which is a BASTARD of a control. How many of you know that in WPF the TabControls VisualTree only keeps the selected item in the VisualTree.

Does that sound bad to you? No, think again (though this only a problem when using DataTemplates, direct TabItem / View combination is ok). So we have several Views which use MeffedMVVM to create a ViewModel within a TabControl. We then change tabs, and guess what the View gets trashed, and when we go back to a previous TabItem, as we are using view 1st and MeffedMVVM, a new ViewModel is created for the View."

Cheval
thank you for replay. I will see this article.
ebattulga