如何在WPF中禁用用户控件的大小调整
我有Usercontrol.我想禁用其调整大小. 用户控件为:
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">
我知道有一个名为
ResizeMode ="NoResize"
ResizeMode="NoResize"
.但是在UserControl中不可用.有任何建议吗?
.But it is not available in UserControl.Any suugestion?
您已将Width
和Height
设置为Auto
,所以我想您应该允许控件占用所需的空间,但不能更多.
You have Width
and Height
set to Auto
, so I guess you was to allow the control to take as much space as needed but not more.
此外,UserControl
本身并不调整大小,而是取决于其一部分的布局.
Also, UserControl
is not resizing by itself, but depends upon the layout that it's part of.
因此,解决问题的最快方法是设置HorizontalAlignment="Left"
和VerticalAlignment="Top"
.但是,您应该考虑应用程序的整体布局以及UC如何受到UI的其他组件的影响.
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.