locked
Width question RRS feed

  • Question

  • The width of the control below is 1000.  None of the contained controls specifies a width.  Shouldn't they stretch to fill their container?  For each control, Blend says Width=Auto, HorizontialAlignment=Stretch.  Sorry for asking dumb questions I'm a flaming beginner.
    Thanks!

    <yada yada Width="1000">
    	
        <Grid x:Name="LayoutRoot" Background="White">
            <controls:TreeView x:Name="TreeView1" ItemsSource="{Binding}" BorderThickness="6,1,1,1">
                <controls:TreeView.ItemTemplate>
                    <common:HierarchicalDataTemplate ItemsSource="{Binding Replies}">
                     	<StackPanel Orientation="Vertical">
                        	<TextBlock Text="{Binding Date, Mode=OneWay}" Margin="10,10,0,0" Height="10" />
                        	<Rectangle Stroke="Black"  Fill="#FFD2C7C7" Height="25"/>
                     		<TextBlock Text="{Binding Comment}" />
                     		<TextBox x:Name="ReplyText" />
                     		<Button Content="Reply" Click="ReplyButton_Click" />
    					</StackPanel>
                     
                    </common:HierarchicalDataTemplate>
                </controls:TreeView.ItemTemplate>
            </controls:TreeView>
        </Grid>
    </UserControl>

    Monday, August 24, 2009 3:26 PM

All replies

  • Hi Sam, you can set the width and height to stretch ( the 4th icon on the right on the alignment section of the Properties>Layout panel) and the width and height to auto. This will automatically stretch the child controls to the size of their parent container.
    Monday, August 24, 2009 3:32 PM
  • Hi, Thanks for answering.
    The width box in the layout tab for the treeview control says Auto(1000).
    The width box in the layout tab for the stackpanel says Auto(37). I assume the 37 means the calculated width of the container at design time(??).  If that is true, I don't know what container is restricting the width to 37.
    I forgot to mention that the outer control renders correctly however the inner controls are about 30px.

    Monday, August 24, 2009 3:53 PM
  • Are there any margins being set? That might be the problem
    Monday, August 24, 2009 3:55 PM
  • I dont think so.  The outer control renders correctly.  The problem is that the inner controls don't stretch.
    I added width=1000 on the textblock  and it rendered correctly however I dont want to do that because I want it to resize with the outer control.
    Monday, August 24, 2009 4:14 PM
  • And you have definitely checked the stretch icon?
    Monday, August 24, 2009 4:25 PM
  • Yes.  I think it is the default since there is nothing in the xaml.  Even so, I added:
    <Button Content="Reply" Click="ReplyButton_Click" HorizontalAlignment="Stretch" />

    Monday, August 24, 2009 4:37 PM
  • When I paste your code, everything stretches (width) fine all the way to the edge.
    Monday, August 24, 2009 5:06 PM
  • Would you mind posting the code?
    Monday, August 24, 2009 7:15 PM