-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Description
Bug explanation
I switched my project to 5.3.1 and all the TabControl instances immediately exhibited errors in the Xaml designer "Object reference not set to an instance of an object". My projects use the TabControl extensively and sometimes nest them inside each other.
Additionally, Visual Studio cannot render the TabControl in the Design window.
When I switched back to 5.3.0, the error went away. I tracked it down to the new TabAssist.HeaderBehavior, specifically the default ScrollingTabControlTemplate. I confirmed this by creating a test project with two TabControls, one with TabAssist.HeaderBehavior set to Scrolling and another to Wrapping. The one with Wrapping did not have the error and rendered properly while the other did have the error and would not render.
Also, my more complex application could not switch between tabs at run time. I was not able to create a simplified version to reproduce that specific behavior at run time. I believe addressing the problem in the ScrollingTabControlTemplate will solve this as well.
Analysis
Looking at ScrollingTabControlTemplate, it appears that the new version in 5.3.1 is using internal-only objects. When I copied over the template in my test project and commented out the following lines:
<b:Interaction.Behaviors>
<behaviorsInternal:TabControlHeaderScrollBehavior TabControl="{Binding RelativeSource={RelativeSource TemplatedParent}}" ScrollableContent="{Binding ElementName=ScrollableContent}" />
</b:Interaction.Behaviors>
<internal:PaddedBringIntoViewStackPanel x:Name="ScrollableContent"
ScrollDirection="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(behaviorsInternal:TabControlHeaderScrollBehavior.ScrollDirection)}"
HeaderPadding="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:TabAssist.HeaderPadding)}"
UseHeaderPadding="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:TabAssist.UseHeaderPadding)}">
and also substituted a StackPanel for the internal-only PaddedBringIntoViewStackPanel, the bug went away and my application behaved properly.
I do not understand the use of internal-only objects in a theming style of a public library. How can I style my own controls based on the Material Design in your library if I cannot access the objects that are in the base style? I often make minor tweaks to the styles to suit my needs. The use of inaccessible objects in a public style breaks all the styling guidelines I have ever encountered.
I suspect that I am getting "Object reference not set to an instance of an object" precisely because the objects in question are inaccessible to the designer and my project.
Version
5.3.1 latest stable