Comment:
<UserControl x:Class="MyEditor.MyDialog"
xmlns="http://schemas.Microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.Microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.Microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="152" d:DesignWidth="590" HorizontalContentAlignment="Right" MinWidth="{Binding ElementName=VariableType}" MinHeight="{Binding RelativeSource={RelativeSource Self}}">
<Grid Width="591" Height="147" MinWidth="{Binding ElementName=VariableTypeTextBox}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="137*" />
<ColumnDefinition Width="454*" MinWidth="250" />
</Grid.ColumnDefinitions>
<Button Content="Cancel" Height="23" Margin="0,94,7,0" Name="CancelButton" VerticalAlignment="Top" Click="CancelButton_Click" Grid.Column="1" HorizontalAlignment="Right" Width="75" HorizontalContentAlignment="Center" VerticalContentAlignment="Top" />
<Button Content="Create" Height="23" Margin="0,94,108,0" Name="CreateButton" VerticalAlignment="Top" Click="CreateButton_Click" Grid.Column="1" HorizontalAlignment="Right" Width="75" HorizontalContentAlignment="Center" VerticalContentAlignment="Top" />
<Label Content="Variable Name " Height="28" Margin="0,12,29,0" Name="VariableName" VerticalAlignment="Top" HorizontalAlignment="Right" Width="96" Target="{Binding}" HorizontalContentAlignment="Right" />
<TextBox Height="29" Margin="0,11,7,0" Name="VarNameTextBox" VerticalAlignment="Top" KeyDown="OnKeyDownHandler" MouseLeave="MouseLeaveHandler" LostFocus="LostFocusHandler" Grid.Column="1" HorizontalAlignment="Stretch" />
<Label Content="Variable Type" Height="28" Margin="0,0,29,73" Name="VariableType" VerticalAlignment="Bottom" HorizontalContentAlignment="Right" HorizontalAlignment="Right" Width="96" />
<TextBox Height="23" Margin="0,51,7,0" Name="VariableTypeTextBox" VerticalAlignment="Top" IsReadOnly="True" Background="Silver" Foreground="Black" Grid.Column="1" HorizontalAlignment="Stretch" Width="AUTO" />
</Grid>
Vous avez collé le code XAML pour une UserControl
, mais votre question concerne une Window
. Ainsi, vous devrez placer votre contrôle UserControl dans une fenêtre configurée pour interdire le redimensionnement.
Une fenêtre WPF a une propriété ResizeMode, qui peut être l'une des suivantes:
Vous voudrez NoResize.
Exemple:
<Window x:Class="MyEditor.Views.EditorWindow"
xmlns="http://schemas.Microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.Microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.Microsoft.com/expression/blend/2008"
xmlns:views="clr-namespace:MyEditor"
mc:Ignorable="d"
ResizeMode="NoResize"
Title="Editor Window">
<views:MyDialog />
</Window>
Veuillez consulter la documentation pour plus de détails.
Définissez simplement les propriétés MinWidth/MaxWidth et MinHeight/MaxHeight sur la valeur requise.
Pour désactiver: ResizeMode = "CanMinimize"
<Window x:Class="XXXXXX.MainWindow"
xmlns="http://schemas.Microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.Microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.Microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:XXXXXXX"
mc:Ignorable="d"
WindowState="Maximized"
ResizeMode="CanMinimize"
Title="Window">