如何在WPF中禁用用户控件的大小调整 [英] How to disable resizing of user control in WPF

查看:409
本文介绍了如何在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?

推荐答案

您已将WidthHeight设置为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.

这篇关于如何在WPF中禁用用户控件的大小调整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆