Search code examples
wpfuser-controlsdynamic-resizing

How to disable resizing of user control in WPF


I have Usercontrol.I want to disable its resizing. The usercontrol is:

<UserControl x:Class="DocumentUpload"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:telerikGrid="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView" 
      xmlns:telerikGrid1="clr-namespace:Telerik.Windows.Controls.GridView;assembly=Telerik.Windows.Controls.GridView" 
      xmlns:telerikInp="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input" 
      xmlns:telerikNav="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation" 
      xmlns:telerikData="clr-namespace:Telerik.Windows.Data;assembly=Telerik.Windows.Data" 
      xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
       Height="auto" Width="auto" MaxWidth="520">

I got to know that there is property called

ResizeMode="NoResize"

.But it is not available in UserControl.Any suugestion?


Solution

  • You have Width and Height set to Auto, so I guess you want to allow the control to take as much space as needed but not more.

    Also, UserControl is not resizing by itself, but depends upon the layout that it's part of.

    So, the quickest way to fix your issue would be to set HorizontalAlignment="Left" and VerticalAlignment="Top". But you should consider the whole layout of your application and how the UC is affected by-/affects on other components of the UI.