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. Image for the cookie policy date

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

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

4 Replies

AK Ashok Kumar Murugesan Syncfusion Team September 8, 2016 12:23 PM UTC

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. 



JR James Randle September 8, 2016 02:35 PM UTC

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!



JR James Randle September 8, 2016 03:24 PM UTC

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.



AK Ashok Kumar Murugesan Syncfusion Team September 9, 2016 11:26 AM UTC

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.  


Loader.
Up arrow icon