Fwd: [CodeProject] TabControlEx within an UserControl cause problem for displaying first tab (mainly for Eric)

173 views
Skip to first unread message

Sacha Barber

unread,
Oct 16, 2009, 1:12:22 PM10/16/09
to wpf-di...@googlegroups.com
Here it is (Mainly for Eric)

Forwarded conversation
Subject: [CodeProject] TabControlEx within an UserControl cause problem for displaying first tab
------------------------

From: The Code Project forums <for...@codeproject.com>
Date: Fri, Oct 16, 2009 at 3:13 PM
To: Sacha Barber <sacha....@gmail.com>


Do not hit 'reply' to this email: To reply, click here.

Gautier Boder has posted a new comment at "Article "WPF: If Heineken did MVVM Frameworks Part 6 of n"":

Hi,

We're trying to use your TabControlEx within our application in cohabitation with the MVVM pattern but instead of having it within a Window element we declared it within an UserControl element. The result is that the first displayed tab (the one added on the application's startup) is selected but has no content shown.

If you look at the visual tree (using snoop) the ContentPresenter that should be showing the view matching the selected workspace viewmodel just doesn't exists at all. The Grid has no children.

Digging further into the implementation of your TabControlEx we've found that when you reside within a Window first the data binding is done and the only the template is applied. Being within an UserControl works exactly the opposite, first the template is applied and then only the DataBinding is done.

This cause the template to be applied with an empty Items collection at this point of time.

We don't know if this could cause the problem of my "empty" tab as when we're using the native TabControl control directly also in combination with MVVM, DataTemplate and ViewModel it works ... Weirdo isn't ? Do Microsoft have a really hidden logic within its control that isn't called just by calling the base constructor? Or is their some hidden events that we're not able to overload or handle when overwriting the control?

Any thoughts or digging way would be really appreciated.

Thanks to anyone who used this TabControlEx to post their feedback.

Gautier

Note: This message has been sent from an unattended email box.

----------
From: Sacha Barber <sacha....@gmail.com>
Date: Fri, Oct 16, 2009 at 6:08 PM
To: wpf-di...@googlegroups.com


TabControlEx (Eric what do you make of this one) feel free to answer the question in the forum.
--
Sacha Barber
sacha....@gmail.com




--
Sacha Barber
sacha....@gmail.com

Eric Burke

unread,
Oct 16, 2009, 10:09:57 PM10/16/09
to wpf-di...@googlegroups.com
I replied to the thread.  The upshot is the _itemsHolder.Children is getting cleared (not sure why) so handling this.Loaded and calling UpdateSelectedItem() does the trick.

Eric Burke

unread,
Oct 16, 2009, 10:16:32 PM10/16/09
to wpf-di...@googlegroups.com
(also posted this to the forum)

OK, I just dug into it a little bit more. The upshot is that in the UC case, the setting of the ItemsSource *after* ApplyTemplate causes a Refresh() of the CollectionView which the ItemsControl is using. The result of this is a CollectionChanged event with Action = Reset, which my code handles and clears _itemsHolder.Children. So the bottom line is: handle Loaded and update the selected item, just in case. ;)

Here's the stack:

> TabControlTest.exe!TabControlTest.TabControlEx.OnItemsChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e = {System.Collections.Specialized.NotifyCollectionChangedEventArgs}) Line 72 C#
  PresentationFramework.dll!System.Windows.Controls.ItemsControl.OnItemCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) + 0x6a bytes
  [Native to Managed Transition]
  [Managed to Native Transition]
  PresentationFramework.dll!System.Windows.Data.CollectionView.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs args = {System.Collections.Specialized.NotifyCollectionChangedEventArgs}) + 0x29 bytes
  PresentationFramework.dll!System.Windows.Controls.ItemCollection.System.Windows.IWeakEventListener.ReceiveWeakEvent(System.Type managerType, object sender, System.EventArgs e) + 0xc2 bytes
  WindowsBase.dll!System.Windows.WeakEventManager.DeliverEventToList(object sender = {System.Windows.Data.ListCollectionView}, System.EventArgs args = {System.Collections.Specialized.NotifyCollectionChangedEventArgs}, System.Windows.WeakEventManager.ListenerList list = {System.Windows.WeakEventManager.ListenerList}) + 0x59 bytes
  WindowsBase.dll!System.Windows.WeakEventManager.DeliverEvent(object sender, System.EventArgs args) + 0xc9 bytes
  WindowsBase.dll!System.Collections.Specialized.CollectionChangedEventManager.OnCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs args) + 0xa bytes
  PresentationFramework.dll!System.Windows.Data.CollectionView.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs args = {System.Collections.Specialized.NotifyCollectionChangedEventArgs}) + 0x29 bytes
  PresentationFramework.dll!System.Windows.Data.ListCollectionView.RefreshOverride() + 0x1ae bytes
  PresentationFramework.dll!System.Windows.Data.CollectionView.RefreshInternal() + 0x10 bytes
  PresentationFramework.dll!System.Windows.Data.CollectionView.Refresh() + 0x41 bytes
  PresentationFramework.dll!System.Windows.Data.CollectionView.EndDefer() + 0x1b bytes
  PresentationFramework.dll!System.Windows.Data.CollectionView.DeferHelper.Dispose() + 0x13 bytes
  PresentationFramework.dll!System.Windows.Controls.ItemCollection.SetCollectionView(System.Windows.Data.CollectionView view) + 0x79 bytes
  PresentationFramework.dll!System.Windows.Controls.ItemCollection.SetItemsSource(System.Collections.IEnumerable value) + 0x41 bytes
  PresentationFramework.dll!System.Windows.Controls.ItemsControl.OnItemsSourceChanged(System.Windows.DependencyObject d, System.Windows.DependencyPropertyChangedEventArgs e) + 0xad bytes

<snip>


Sacha Barber

unread,
Oct 17, 2009, 12:02:54 AM10/17/09
to wpf-di...@googlegroups.com
Saw that one, thanks Eric. Ill update the code very soon
--
Sacha Barber
sacha....@gmail.com
Reply all
Reply to author
Forward
0 new messages