Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Making control size the same as grid
2 replies. Latest Post by gp100mk on October 26, 2008.
(0)
gp100mk
Member
7 points
58 Posts
10-26-2008 5:42 AM |
I'm new to Silverlight and am trying to use the following xaml to make make my StackPanel take the same width as the containing Grid:-
<Grid x:Name="LayoutRoot" Width="200">
In the above example my grid is of Width 200, and the StackPanel has its wdth set to Auto. However, this does not size to the width of the grid as expected. How can this be done? Eventually I want this to be part of a UserControl, so the width of 200 will not be hard-coded.
pkr2000
Participant
1219 points
377 Posts
10-26-2008 7:01 AM |
I believe it's because a grid contents are held in rows and columns and not in a simple child way that your code is hoping for. E.g. if you change Grid to Canvas your code will probably work. Other than that you need to specify the row your child goes in then you do tricks like col/row spans to virtually ignore the rows/cols.
10-26-2008 7:06 AM |
I managed to get this to work by setting the following on the StackPanel:- HorizontalAlignment="Stretch"
HorizontalAlignment