I've got a root UserControl that is 300 high.
Inside that I have a Border that I want to expand to the size of its own controls, so if I stack in more controls, it will expand -- less controls, it will contract.
However when I set it to "Auto" it expands it out to the size of its parent container instead of the size of its child controls.
How can I get Border to expand and contract to the size of its child controls, something like the functionality of an HTML table?
<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>
Wrap it in a StackPanel should do it:
<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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With