--- title: "How to: Automatically Size a Window to Fit Its Content" description: Learn how to set the property that specifies how a window resizes to fit its content in Windows Presentation Foundation (WPF). ms.date: "03/30/2017" dev_langs: - "csharp" - "vb" helpviewer_keywords: - "resizing windows to fit content [WPF]" - "windows [WPF], resizing to fit content" - "sizing windows to fit content [WPF]" ms.assetid: 333ca72a-c2f3-4414-9303-3fdabaaa1b32 --- # How to: Automatically Size a Window to Fit Its Content This example shows how to set the property to specify how a window resizes to fit its content. ## Example [!code-csharp[HOWTOWindowManagementSnippets#SetWindowSizeToContentPropertyCODE](~/samples/snippets/csharp/VS_Snippets_Wpf/HOWTOWindowManagementSnippets/CSharp/MainWindow.xaml.cs#setwindowsizetocontentpropertycode)] [!code-vb[HOWTOWindowManagementSnippets#SetWindowSizeToContentPropertyCODE](~/samples/snippets/visualbasic/VS_Snippets_Wpf/HOWTOWindowManagementSnippets/visualbasic/mainwindow.xaml.vb#setwindowsizetocontentpropertycode)]