GroupBox
Here is a sample template for groupbox in silverlight (mostly from groupbox in WPF)
you can download the source here
Categories: Silverlight
Here is a sample template for groupbox in silverlight (mostly from groupbox in WPF)
you can download the source here
Hello,
I think the spacing before text “Options” in groupbox looks a lit bit far…
Hi,
The template from WPF doesnt seem to work as it does in WPF, if you notice the right hand top BorderThickness is bit wider than the rest. not sure why it is doing that. playing around with the column widths in the Grid in the Template would help
Hi,
Thanks for the control, great work. I was having a problem in Firefox getting it to render the border and header (didn’t try IE). The border and header weren’t showing only the content. I added the following ctor to match your other controls and it worked just fine.
public GroupBox()
{
DefaultStyleKey = typeof(GroupBox);
}
yes, we need to do that as that is breaking change in beta2
I had to comment out BorderBrush and BorderBrushProperty to get this to work with latest Silverlight 2.0.
Thanks for the comment. I did not get a chance to update this to beta2. This is very helpful
Hi,
This is very good & useful article.
But this GroupBox is not working under DataTemplate.
Is there any way to add an eventhandler to this GroupBox
grp_Target(object sender, DataTransferEventArgs e) will e defined in my C# file.
Thanks
This groupBox is not working under DataTemplate.
——
I am not sure what you meant. did you make the necessary changes to work in the released version of silverlight, like creating a folder called themes and moving the generic.xaml file into that folder?
When i use it in Silverlight RC0, I can only see the radiobutton, but groupbox.
Hi AK,
Name the 2 border elements in generic.xaml border and border1 for ex
Add code to groupbox.cs similar to the following
In the constructor
add an eventhandler
IsEnabledChanged += new DependencyPropertyChangedEventHandler(GroupBox_IsEnabledChanged);
declare 2 variables in the class as following
Border b;
Border b1;
//event handler
void GroupBox_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
{
b.BorderBrush = new SolidColorBrush(Colors.Magenta);
b1.BorderBrush = new SolidColorBrush(Colors.Magenta);
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
b = GetTemplateChild(“border”) as Border;
b1 = GetTemplateChild(“border1″) as Border;
}
looks like template is not being applied. did you create a Themes folder and move generic.xaml into that?
for it to work in RTM
1. create a folder called themes and move generic.xaml into that
2. replace ContentPresenter with ContentControl in generic.xaml
3. Add the following constructor to groupbox.cs
public GroupBox()
{
DefaultStyleKey = typeof(GroupBox);
}
Hi, lee
I find that if i set the groupbox’s isEnabled property to false,
the Header’s color is still black.
Do you have any solutions to change the color to gray when the isEnabled is set to false?
Thanks
Hi I’ve tried you control but it gives me an error “Object reference not set to an instance of an object.” at this line: HeaderContainer.SizeChanged += HeaderContainer_SizeChanged;
I’m using it in the latest version of silverlight 2.0
I am thinking, Template is not being applied.
did you do this
for it to work in RTM
1. create a folder called themes and move generic.xaml into that
2. replace ContentPresenter with ContentControl in generic.xaml
3. Add the following constructor to groupbox.cs
public GroupBox()
{
DefaultStyleKey = typeof(GroupBox);
}
It doesn’t work i have the same error, but if i comment that line “HeaderContainer.SizeChanged += HeaderContainer_SizeChanged;” it show’s the content in the groupbox but not the header.
Mybe I have this error because all the files are in the same projject the generic.xaml and the coude behind file it’s no timported from a diffrent project like in your test sample.