当窗口在wpf中最大化时,如何在窗口中展开所有内容?

时间:2011-05-20 14:19:57

标签: c# wpf screen maximize

我的主翼有丝带标签和数据网格。当窗口最大化以适应屏幕时,如何最大化窗口中的所有内容?我正在尝试使用viewbox但它不起作用。

<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>

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

帮助。

先谢谢

2 个答案:

答案 0 :(得分:1)

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">

答案 1 :(得分:0)

我只是想出去猜猜你需要将你的视窗固定到控件的两侧。这是保证金属性。

您的ViewBox应该在其XAML中看起来像Margin=5,5,5,5