当窗口在 wpf 中最大化时,如何拉伸窗口中的所有内容

本文关键字:窗口 何拉伸 wpf 最大化 | 更新日期: 2023-09-27 17:56:58

我有我的主要翼带有功能区选项卡和数据网格。当窗口最大化以适合屏幕时,如何最大化窗口中的每一个薄?我正在尝试使用视图框,但它不起作用。

<Viewbox Stretch="Uniform">
        <Grid x:Name="LayoutRoot">
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="auto"/>
            </Grid.RowDefinitions>

                <ribbon:Ribbon x:Name="Ribbon">
                    <ribbon:RibbonTab x:Name="HomeTab" 
                                  Header="Home">
                        <ribbon:RibbonGroup x:Name="Group1" 
                                        Header="Refresh">
                            <ribbon:RibbonButton x:Name="BtmRefresh"
                                             LargeImageSource="Images'refresh.png"
                                             Label="Refresh" Margin="25,0,30,0" Click="BtmRefresh_Click" />
                        </ribbon:RibbonGroup>
                    </ribbon:RibbonTab>
                </ribbon:Ribbon>

            <StackPanel Name="PanelDataGrid" Height="Auto" >
                    <DataGrid  AutoGenerateColumns="False" Margin="0,138,0,0" Name="dataGrid" Height="Auto" ItemsSource="{Binding}"  SelectionUnit="Cell"   AlternatingRowBackground="#FFDFE9F5"
                 SelectionMode="Single" ColumnWidth="68"  HeadersVisibility="Column" RowBackground="{x:Null}" >
                        <DataGrid.Background>
                            <ImageBrush ImageSource="/GridCellColor;component/Images/barcode.png" />
                        </DataGrid.Background>
                        <DataGrid.Columns >
                            <DataGridTextColumn Binding="{Binding Path=Job_Num}"  Header="Job Nº" IsReadOnly="True" Width="1*" />
                            <DataGridTextColumn Binding="{Binding Path=Product_Code}" IsReadOnly="True" Header="Product" Width="1*" />
    </DataGrid.Columns>
                    </DataGrid>
                 </StackPanel>
        </Grid>
    </Viewbox>

我尝试在网格标签之前添加

帮助。

提前致谢

当窗口在 wpf 中最大化时,如何拉伸窗口中的所有内容

StretchDirection="Both"添加到您的 ViewBox,它应该可以工作

// Will Stretch it and keep the ratio the same
<Viewbox Stretch="Uniform" StretchDirection="Both">

// Will Stretch it to fill full screen regardless of ratio
<Viewbox Stretch="Fill" StretchDirection="Both">

我只是想出去猜测你需要将视框锚定到控件的两侧。这是边距属性。

你的ViewBox应该在 XAML 中具有类似于 Margin=5,5,5,5 的内容。