我正在开发WPF应用程序;我的问题是当我最大化窗口并在其最小化/调整大小之后;该控件在最大化上运行良好,但是当我最小化/调整窗口大小时,控件(文本块,组合框)不保持最大尺寸。 我怎样才能使控件的大小最小化?
以下是我的XAML代码的一个示例:
<UserControl x:Class="MyNamespace.UC.Suppliers_Insert"
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:local="clr-namespace:MyNamespace.UC"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<DockPanel Name="MainDock" LastChildFill="True" DataContext="{Binding Suppliers_Insert, Source={StaticResource Locator}}"
VerticalAlignment="Stretch"
Height="Auto">
<Grid>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Name="wRow0" Height="*"/>
<RowDefinition Name="wRow1" Height="*"/>
<RowDefinition Name="wRow2" Height="*"/>
<RowDefinition Name="wRow3" Height="*"/>
<RowDefinition Name="wRow4" Height="*"/>
</Grid.RowDefinitions>
<telerik:RadWatermarkTextBox Grid.Column="0" Grid.Row="0" WatermarkContent="Supplier Name" Text="{Binding SupplierModel.Supplier_Name, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"
Style="{StaticResource RadWatermarkTextBoxStyle_UserNamme}" Margin="5,5,5,0" Visibility="{Binding Supplier_Name_Visibility}" IsEnabled="{Binding Supplier_Fields_Enable}"
Validation.ErrorTemplate="{StaticResource MyTemplateError}"/>
<telerik:RadWatermarkTextBox Grid.Column="0" Grid.Row="1" WatermarkContent="Vat Number" Text="{Binding SupplierModel.VAT_Number, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"
Style="{StaticResource RadWatermarkTextBoxStyle_UserNamme}" Margin="5,5,5,0" Visibility="{Binding VAT_Number_Visibility}" IsEnabled="{Binding Supplier_Fields_Enable}"
Validation.ErrorTemplate="{StaticResource MyTemplateError}"/>
<telerik:RadWatermarkTextBox Grid.Column="0" Grid.Row="2" WatermarkContent="Tax Code" Text="{Binding SupplierModel.Tax_Code, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"
Style="{StaticResource RadWatermarkTextBoxStyle_UserNamme}" Margin="5,5,5,0" Visibility="{Binding Tax_Code_Visibility}" IsEnabled="{Binding Supplier_Fields_Enable}"
Validation.ErrorTemplate="{StaticResource MyTemplateError}"/>
<telerik:RadWatermarkTextBox Grid.Column="0" Grid.Row="3" WatermarkContent="External Supplier ID" Text="{Binding SupplierModel.External_Supplier_ID, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"
Style="{StaticResource RadWatermarkTextBoxStyle_UserNamme}" Margin="5,5,5,0" Visibility="{Binding External_Supplier_ID_Visibility}" IsEnabled="{Binding Supplier_Fields_Enable}"
Validation.ErrorTemplate="{StaticResource MyTemplateError}"/>
<telerik:RadWatermarkTextBox Grid.Column="1" Grid.Row="0" Grid.ColumnSpan="2" Grid.RowSpan="3" WatermarkContent="Note" AcceptsReturn="True" Text="{Binding SupplierModel.Note, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"
Style="{StaticResource RadWatermarkTextBoxStyle_UserNamme}" Margin="5,5,5,0" Visibility="{Binding Note_Visibility}" IsEnabled="{Binding Supplier_Fields_Enable}"
Validation.ErrorTemplate="{StaticResource MyTemplateError}"/>
<telerik:RadWatermarkTextBox Grid.Column="1" Grid.Row="1" Grid.ColumnSpan="2" WatermarkContent="Website" Text="{Binding SupplierModel.Website, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"
Style="{StaticResource RadWatermarkTextBoxStyle_UserNamme}" Margin="5,5,5,0" Visibility="{Binding Website_Visibility}" IsEnabled="{Binding Supplier_Fields_Enable}"
Validation.ErrorTemplate="{StaticResource MyTemplateError}"/>
<telerik:RadButton x:Name="rdb_Insert" Grid.Row="3" Grid.Column="3" HorizontalAlignment="Right" Margin="10,0,10,0" VerticalAlignment="Center" Content="{DynamicResource rsBtn_Insert}" Width="75"
Visibility="{Binding InsertButtonVisibility}" Command="{Binding SaveNavigationCommand}" />
<telerik:RadButton x:Name="rdb_Cancel" Grid.Row="4" Grid.Column="3" HorizontalAlignment="Right" Margin="10,0,10,0" VerticalAlignment="Center" Content="{DynamicResource rsBtn_Cancel}" Width="75"
Command="{Binding CancelNavigationCommand}" Visibility="{Binding CancelButtonVisibility}" />
<telerik:RadButton x:Name="rdb_Close" Grid.Row="4" Grid.Column="3" HorizontalAlignment="Right" Margin="10,0,10,0" VerticalAlignment="Center"
Content="{DynamicResource rsBtn_Close}" Width="75" Command="{Binding CancelButtonVisibility}" Visibility="{Binding CloseButtonVisibility}"/>
</Grid>
</Grid>
</DockPanel>
谢谢。
编辑: 我忘记指出UC已进入MainView的StackPanel中。我将SP更改为Grid,现在,当窗口最小化时,内容将正确调整大小。
答案 0 :(得分:0)
我对您的usercontrol进行了调试,为此,我必须删除xaml中使用的命令和样式。我可以看到控件在窗口调整大小上达到最小或最大化。我确定问题出在您应用于控件的样式上。 我使用的代码是:
<DockPanel Name="MainDock" LastChildFill="True"
VerticalAlignment="Stretch"
Height="Auto">
<Grid>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Name="wRow0" Height="*"/>
<RowDefinition Name="wRow1" Height="*"/>
<RowDefinition Name="wRow2" Height="*"/>
<RowDefinition Name="wRow3" Height="*"/>
<RowDefinition Name="wRow4" Height="*"/>
</Grid.RowDefinitions>
<telerik:RadWatermarkTextBox Grid.Column="0" Grid.Row="0" WatermarkContent="Supplier Name" Text="{Binding SupplierModel.Supplier_Name, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"
Margin="5,5,5,0" Visibility="{Binding Supplier_Name_Visibility}" IsEnabled="{Binding Supplier_Fields_Enable}"
/>
<telerik:RadWatermarkTextBox Grid.Column="0" Grid.Row="1" WatermarkContent="Vat Number" Text="{Binding SupplierModel.VAT_Number, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"
Margin="5,5,5,0" Visibility="{Binding VAT_Number_Visibility}" IsEnabled="{Binding Supplier_Fields_Enable}"
/>
<telerik:RadWatermarkTextBox Grid.Column="0" Grid.Row="2" WatermarkContent="Tax Code" Text="{Binding SupplierModel.Tax_Code, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"
Margin="5,5,5,0" Visibility="{Binding Tax_Code_Visibility}" IsEnabled="{Binding Supplier_Fields_Enable}"
/>
<telerik:RadWatermarkTextBox Grid.Column="0" Grid.Row="3" WatermarkContent="External Supplier ID" Text="{Binding SupplierModel.External_Supplier_ID, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"
Margin="5,5,5,0"
/>
<telerik:RadWatermarkTextBox Grid.Column="1" Grid.Row="0" Grid.ColumnSpan="2" Grid.RowSpan="3" WatermarkContent="Note" AcceptsReturn="True" Text="{Binding SupplierModel.Note, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"
Margin="5,5,5,0"
/>
<telerik:RadWatermarkTextBox Grid.Column="1" Grid.Row="1" Grid.ColumnSpan="2" WatermarkContent="Website" Text="{Binding SupplierModel.Website, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"
Margin="5,5,5,0"
/>
<telerik:RadButton x:Name="rdb_Insert" Grid.Row="3" Grid.Column="3" HorizontalAlignment="Right" Margin="10,0,10,0" VerticalAlignment="Center" Width="75"
/>
<telerik:RadButton x:Name="rdb_Cancel" Grid.Row="4" Grid.Column="3" HorizontalAlignment="Right" Margin="10,0,10,0" VerticalAlignment="Center" Width="75"
/>
<telerik:RadButton x:Name="rdb_Close" Grid.Row="4" Grid.Column="3" HorizontalAlignment="Right" Margin="10,0,10,0" VerticalAlignment="Center"
Width="75" />
</Grid>
</Grid>
</DockPanel>