Automatically Size the Main Application Window to Accommodate Its Content
<Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="WPF " SizeToContent="WidthAndHeight"> <StackPanel Height="23" Orientation="Horizontal"> <Button Content="Button 1" Margin="2" /> <Button Content="Button 2" Margin="2" /> <Button Content="Button 3" Margin="2" /> <Button Content="Button 4" Margin="2" /> <Button Content="Button 5" Margin="2" /> </StackPanel> </Window>