EisenbergEffect
Topic Author
Posts: 19
Joined: 22 Mar 2013, 15:09

Style Inheritance

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:
<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>
 
User avatar
sfernandez
Site Admin
Posts: 1918
Joined: 22 Dec 2011, 19:20

Re: Style Inheritance

25 Mar 2013, 22:39

The cause that makes your buttons not visible is because in NoesisGUI there is no default (theme) style to rely on for the properties that are not set in your Style. So when you set the Style property of a Control, the Style object must have a Setter for the Template property with a valid ControlTemplate defined, or be BasedOn a Style with the Template property correctly set. Otherwise the Control would not have a visual tree to be rendered.

Looking at the Dependency Property Value list described in WPF documentation: http://msdn.microsoft.com/en-us/library ... px#listing, NoesisGUI doesn't implement item 9.

Other users had problems in the past with the same issue, causing lots of confusion because their controls were not rendered, so we decided to incorporate that feature in the final 1.0 release. We will provide a simple default style, so all controls (currently implemented in NoesisGUI) get a valid ControlTemplate and are always rendered.
 
EisenbergEffect
Topic Author
Posts: 19
Joined: 22 Mar 2013, 15:09

Re: Style Inheritance

26 Mar 2013, 15:00

I had a feeling it was something like that. I think it will make a big difference to always have a default control template. One thing that makes it twice as confusing in Unity is that you can assign a resource file to the NoesGUI script. So, I really did expect those styles to flow through since I had explicitly set them, but they didn't.
 
User avatar
sfernandez
Site Admin
Posts: 1918
Joined: 22 Dec 2011, 19:20

Re: Style Inheritance

02 Apr 2013, 01:52

So, I really did expect those styles to flow through since I had explicitly set them, but they didn't.
Do you mean you expect that styles defined in the resource file behave as the default (theme) styles?
 
EisenbergEffect
Topic Author
Posts: 19
Joined: 22 Mar 2013, 15:09

Re: Style Inheritance

05 Apr 2013, 12:38

Yes, given the Unity configuration step of adding that resource file on the script, I thought those would flow through as the default styles. I don't really care if that's how it works in the final version, as long as there is a default step of styles...and as long as I can replace that somewhere.

Who is online

Users browsing this forum: Google [Bot] and 1 guest