简体   繁体   中英

How can I stretch everything in my window when window is maximized in wpf?

I have got my main wingow with ribbon tabs and a datagrid. How can I maximize everythin in the window when window is maximized to fit the screen?I am trying to use viewbox but its not working.

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

And I tried adding before grid tag

Help.

Thanks in Advance

Add StretchDirection="Both" to your ViewBox and it should work

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

I'm just going to go out and guess that you need to anchor your viewbox to the sides of the control. This is the margin property.

Your ViewBox should have something that looks like Margin=5,5,5,5 in it's XAML.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM