试图让我的Expander通过帧控制来调整大小

时间:2017-04-28 15:49:30

标签: wpf xaml

我正在创建一个加载在Frame控件内部的XAML页面。它包括Expander控件。当用户调整窗口大小时,我需要扩展器和Expander的所有内容水平调整大小。有人有什么建议吗?

 <Grid>
    <StackPanel x:Name="Stackpanel1" HorizontalAlignment="Stretch" Margin="8,8,0,10" Orientation="Horizontal" VerticalAlignment="Stretch">
        <Expander ExpandDirection="Right" IsExpanded="True" Expanded="Expander_Expanded">
            <Expander.Header>
                <TextBlock Text="Daily" RenderTransformOrigin=".5,.5">
                    <TextBlock.LayoutTransform>
                        <RotateTransform Angle="90" />
                    </TextBlock.LayoutTransform>
                </TextBlock>
            </Expander.Header>
            <StackPanel Orientation="Vertical"
                        TextBlock.Foreground="{DynamicResource MaterialDesignBody}"
                        Margin="8,0,16,0" Height="610">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="1*"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Grid Grid.Row="0" Grid.Column="0" Width="Auto">
                        <materialDesign:Card Grid.Column="1" Padding="5" UniformCornerRadius="8" Margin="0,5,0,0" >
                            <StackPanel Orientation="Horizontal"
                        TextBlock.Foreground="{DynamicResource MaterialDesignBody}"
                        Margin="8,24,16,24">
                                <TextBox x:Name="txtReprint" MinWidth="300"/>
                                <Button x:Name="btnReprint" Content="Re-Print" Margin="10,0,0,0" Width="156" Click="btnReprint_Click"/>
                            </StackPanel>
                        </materialDesign:Card>
                    </Grid>                       
                    <materialDesign:Card Grid.Column="0" Grid.Row="1" Padding="5" UniformCornerRadius="8" Margin="0,5,0,0" VerticalAlignment="Top" Height="508">
                        <StackPanel Orientation="Vertical" 
                        TextBlock.Foreground="{DynamicResource MaterialDesignBody}"
                        Margin="8,0,16,0" VerticalAlignment="Top">
                            <Label x:Name="lblPriority" Content="Priority" VerticalAlignment="Top"/>
                            <DataGrid x:Name="dgvPriority" Width="467" Height="414"/>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="1*"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                <Button x:Name="btnPriorityRefresh" Content="Refresh" Grid.Column="0" Margin="5,10,5,0" Click="btnPriorityRefresh_Click"/>
                                <Button x:Name="btnPriorityPrint" Content="Print" Grid.Column="1" Margin="5,10,5,0" Click="btnPriorityPrint_Click"/>
                            </Grid>
                        </StackPanel>
                    </materialDesign:Card>
                    <materialDesign:Card Grid.Column="1" Grid.Row="1" Padding="5" UniformCornerRadius="8" Margin="5,5,0,0" VerticalAlignment="Top" Height="508">
                        <StackPanel Orientation="Vertical" 
                        TextBlock.Foreground="{DynamicResource MaterialDesignBody}"
                        Margin="8,0,16,0" VerticalAlignment="Top">
                            <Label x:Name="lblGround" Content="Ground" VerticalAlignment="Top"/>
                            <DataGrid x:Name="dgvPGround" Width="467" Height="414" HorizontalAlignment="Stretch"/>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="1*"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                <Button x:Name="btnGroundRefresh" Content="Refresh" Grid.Column="0" Margin="5,10,5,0" Click="btnGroundRefresh_Click"/>
                                <Button x:Name="btnGroundPrint" Content="Print" Grid.Column="1" Margin="5,10,5,0" Click="btnGroundPrint_Click"/>
                            </Grid>
                        </StackPanel>
                    </materialDesign:Card>                     
                </Grid>
            </StackPanel>
        </Expander>
        <Border Background="{DynamicResource MaterialDesignDivider}" Width="1" VerticalAlignment="Stretch" SnapsToDevicePixels="True" />
        <Expander ExpandDirection="Right" Expanded="Expander_Expanded">
            <Expander.Header>
                <TextBlock Text="Special Projects" RenderTransformOrigin=".5,.5">
                    <TextBlock.LayoutTransform>
                        <RotateTransform Angle="90" />
                    </TextBlock.LayoutTransform>
                </TextBlock>
            </Expander.Header>
            <materialDesign:Card Grid.Column="1" Grid.Row="1" Padding="5" UniformCornerRadius="8" Margin="5,5,5,5" VerticalAlignment="Top" Height="603">
                <StackPanel Orientation="Vertical"
                        TextBlock.Foreground="{DynamicResource MaterialDesignBody}"
                        Margin="8,24,16,3">
                    <Label x:Name="lblSpecialProjects" Content="Special Projects"/>
                    <DataGrid x:Name="dgvNAB" Width="467" Height="477" Margin="0,5,0,0"/>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Button x:Name="btnNABRefresh" Content="Refresh" Grid.Column="0" Margin="5,10,5,0" Click="btnNABRefresh_Click"/>
                        <Button x:Name="btnNABPrint" Content="Print" Grid.Column="1" Margin="5,10,5,0" Click="btnNABPrint_Click"/>
                    </Grid>
                </StackPanel>
            </materialDesign:Card>
        </Expander>
    </StackPanel>
</Grid>

1 个答案:

答案 0 :(得分:0)

您可以使用Grid并创建列,而不是StackPanel。每个Expander都放在一个单独的列中,这样你可以根据窗口大小调整它们。