tags:

views:

47

answers:

1

It seems like everyone has their own GroupBox control for Silverlight. Which one would you recommend.

+1  A: 

You could just stick with a regular HeaderedContentControl from the Silverlight Toolkit and style it to look like a group box:

GroupBox

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:s="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
                    xmlns:t="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"&gt;
    <Style x:Key="GroupBox" TargetType="t:HeaderedContentControl">
        <Setter Property="BorderBrush" Value="LightGray" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="Background" Value="White" />
        <Setter Property="Foreground" Value="Black" />
        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        <Setter Property="VerticalContentAlignment" Value="Stretch"/>
        <Setter Property="Padding" Value="4" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="t:HeaderedContentControl">
                    <Grid Background="{TemplateBinding Background}">                                
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <Border BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                CornerRadius="4"
                                Margin="0,8,0,0" 
                                Grid.RowSpan="2"  />
                        <s:Label Background="{TemplateBinding Background}"
                                 Content="{TemplateBinding Header}" 
                                 ContentTemplate="{TemplateBinding HeaderTemplate}" 
                                 HorizontalAlignment="Left" 
                                 Margin="8,0,0,0" 
                                 Grid.Row="0" />
                        <ContentPresenter Content="{TemplateBinding Content}" 
                                          ContentTemplate="{TemplateBinding ContentTemplate}" 
                                          HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                          VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
                                          Margin="{TemplateBinding Padding}" 
                                          Grid.Row="1" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
Josh Einstein
That's close enough for me. But why didn't they just use the normal name for that kind of control?
Jonathan Allen
I guess cause they're ugly and Silverlight wanted a fresh start. :) WPF has a GroupBox though.
Josh Einstein
Which is just as ugly before it's styled.
Jonathan Allen
Right, I just meant that even though it's ugly it still seems like it should be there if for no other reason than parity with WPF.
Josh Einstein