Style Inheritance
Posted: 25 Mar 2013, 22:03
I'm seeing some unexpected behavior in style inheritance. I'm working primarily in Unity 3d, but have also tested this in the XamlPlayer. Whenever I create a locally scoped, implicit style for Button, the buttons declared inside that scope disappear. My guess is that the implicit style is somehow nulling out the control template for the button, rather than inheriting it from the parent scope. I'm not sure. But, even the simplest of implicit styles causes the control to no longer render. I've compared this to the WPF behavior using Kaxaml to make sure that I was definitely seeing different behavior from Microsoft's implementation. Here's some sample Xaml that will demonstrate the bug:
Code: Select all
<Border xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch">
<Border.Resources>
<Style TargetType="{x:Type Button}">
<Setter Property="Margin" Value="4" />
<Setter Property="Height" Value="40" />
<Setter Property="Width" Value="40" />
</Style>
</Border.Resources>
<DockPanel>
<Border DockPanel.Dock="Left">
<StackPanel Width="50px">
<Button Content="1"/>
<Button Content="2"/>
<Button Content="3"/>
<Button Content="4"/>
<Button Content="5"/>
</StackPanel>
</Border>
</DockPanel>
</Border>