如何在wpf大小调整

时间:2015-05-19 21:43:58

标签: wpf xaml user-controls

在我的wpf项目中,我有一个主窗口(Mainwindow.xaml)文件,剩下的所有窗口都是用户控件。如果我单击mainwindow.xaml的任何菜单,则相应的用户控件将显示在mainwindow.xaml表单中。

我的要求是,当调整usercontrol窗口的大小时,我需要调整所有控件宽度(即文本框,组合框等等)。我怎样才能做到这一点。

1 个答案:

答案 0 :(得分:1)

首先,动态调整大小所需的组件不应具有固定大小。你应该把常规放入网格并将宽度/高度设置为&#34;自动&#34; /&#34; x *&#34; /对齐以拉伸...... <UserControl ...> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="1*" /> <ColumnDefinition Width="2*" /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="2*"/><!--2/5 of total height--> <RowDefinition Height="3*"/> </Grid.RowDefinitions> <TextBlock Grid.Column="1" Grid.Row="1">Text </TextBlock> <TextBox Grid.Column="2" >Enter</TextBox> <TextBox Grid.Row="2" Grid.ColumnSpan="2">Button 5 Button 5 Button 5 Button 5</TextBox> </Grid> </UserControl>

<Grid Width="Auto" HorizontalAlignment="Stretch"> <ContentControl ..." /> </Grid>

相关问题