views:

87

answers:

2

I have a silverlight stackpanel and i want to set its width to 100%.

i'm adding the stackpanel dynamically (C#)

+2  A: 

Try setting HorizontalAlignment to "Stretch" on your StackPanel and make sure your containing element is also the width you expect.

Dave Markle
"Stretch" is the default value anyway so there shouldn't be a need to set it all. You're correct though, its probably the containing element that Gaby really needs to be looking at.
AnthonyWJones
True, I'm just thinking that maybe he's got some style defined somewhere else that un-sets it...
Dave Markle
A: 
private void CreateMyDynamicStackPanel()
{
    StackPanel MyStackPanel = new StackPanel();
    MyStackPanel.HorizontalAlignment = HorizontalAlignment.Stretch;
    MyStackPanel.Width = 300;
}

Instead of 300, use a property of the parent container?

Tobiasopdenbrouw
I'm loading all the page dynamically and the stackpanel is added on the constructor of the page, so the parent width will be N\A and the actualWidth is equal zero.
Gaby
What is the current behaviour/code?
Tobiasopdenbrouw