How do I make a Silverlight container expand / contract to the size of its child controls?

I have a root UserControl whose height is 300.

Inside, that I have a border that I want to expand to the size of my own controls, so if I stack more controls, it will expand - fewer controls, it will shrink.

However, when I set it to Auto, it expands it to the size of its parent container, and not the size of its child controls.

How can I get Border to expand and contract the size of its child controls, something like HTML table functionality?

<UserControl   x:Class="Second105.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:basics="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
    Width="400" Height="300">
    <Grid x:Name="LayoutRoot" Background="White">
        <Border 
            Background="Tan" 
            CornerRadius="10" 
            Padding="10"
            Width="300" 
            Height="Auto">
        <StackPanel>
                <TextBlock HorizontalAlignment="Center" Margin="0 0 0 5">Please select a <Run FontStyle="Italic">week day</Run>:</TextBlock>
            <basics:Calendar
                Name="theCalendar" 
                SelectedDatesChanged="Calendar_SelectedDatesChanged"/>
            <TextBlock
                Name="theMessage"
                Margin="0 10 0 0"
                HorizontalAlignment="Center"
                Text="..."/>
        </StackPanel>
        </Border>
    </Grid>
</UserControl>
+5
source share
1 answer

StackPanel, :

<UserControl
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:basics="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   Width="400"
   Height="300">
   <Grid x:Name="LayoutRoot" Background="White">
      <StackPanel>
         <Border
            Width="300"
            Height="Auto"
            Background="Tan"
            CornerRadius="10"
            Padding="10">
            <StackPanel>
               <TextBlock HorizontalAlignment="Center" Margin="0 0 0 5">Please select a 
                  <Run FontStyle="Italic">week day
                  </Run>:
               </TextBlock>
               <TextBlock
                  Name="theMessage"
                  HorizontalAlignment="Center"
                  Margin="0 10 0 0"
                  Text="..."/>
            </StackPanel>
         </Border>
      </StackPanel>
   </Grid>
</UserControl>
+6

All Articles