We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

BUG: Tab control creates multiple copies of views when binding tabs to an ObservableCollection via datatemplate

Thread ID:

Created:

Updated:

Platform:

Replies:

125732 Sep 7,2016 09:39 AM Sep 9,2016 07:26 AM WPF 4
loading
Tags: TabControlExt
James Randle
Asked On September 7, 2016 09:39 AM

Hi,
Please see the attached project.

Simply put, when I bind the ItemsSource of the TabControl to an ObservableCollection of view models, more than one view is created, despite there being only one view model in the ObservableCollection.

This is demonstrated in the project by the fact that the following message is output to the console:
View created ... Id = 1
View created ... Id = 2

Clearly, this must mean that two views have been created since the id is incremented each time the TestView constructor is executed.

Please explain why this is the case because it doesn't happen with the Windows TabControl and as far as I can tell, this is pointless ... why waste resources creating two views per view model?!
Furthermore, this introduces subtle errors into any application that expects one view to be created per view model, which is how MVVM is expected to work!

Cheers,
James.

Attachment: TestDataContract_8b0fbb53.rar

Ashok Kumar Murugesan [Syncfusion]
Replied On September 8, 2016 08:23 AM

Hi James,

Thank you for contacting Syncfusion support. 

We were able to reproduce the reported issue "Tab control creates multiple copies of views when binding tabs to an ObservableCollection via datatemplate”. We have created the support incidents under your account to track the status of this issue. Please log on to our support website to check for further updates.

https://www.syncfusion.com/account/login?ReturnUrl=/support/directtrac/incidents 

Regards,
Ashok Kumar M. 


James Randle
Replied On September 8, 2016 10:35 AM

For anyone interested, you can use the following hack to identify the real view

        void TestView_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
                if (!Environment.StackTrace.Contains(@"Syncfusion.Windows.Tools.Controls.TabLayoutPanel.CalculateMaxRowHeight"))
                {
                    //this is the real view
                }
        }

It seems that the 'TabLayoutPanel.CalculateMaxRowHeight' method is responsible for creating the extraneous view. Or it could be the 'TabLayoutPanel.MeasureOverride' method, but this hack works nonetheless.

Cheers!


James Randle
Replied On September 8, 2016 11:24 AM

Actually, this is a better option:

        void Task_CreateNewEntitiesView_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (e.NewValue != null && ((Task_CreateNewEntitiesViewModel)e.NewValue).View == null)
            {
                //this is the correct view (assuming you never assign null to the data context!)
            }
            else
            {
                if (this.DataContext != null) this.DataContext = null;
            }
        }

I have been informed that a fix is on the way though ... intended release on 29th September.


Ashok Kumar Murugesan [Syncfusion]
Replied On September 9, 2016 07:26 AM

Hi James,

Thank you for your update.

The reported issue "Tab control creates multiple copies of views when binding tabs to an ObservableCollection via datatemplate" has been logged as a defect and support incident has been created under your account to track the status of this issue. Please log on to our website to check for further updates.

https://www.syncfusion.com/account/login?ReturnUrl=/support/directtrac/incidents  

Regards,
Ashok Kumar M.  


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;