简体   繁体   English

滚动查看器 WPF XAML 内的网格高度有问题

[英]Having a problem with the Grid height inside scrollviewer WPF XAML

I am having a problem with Grid height inside scrollviewer.我在滚动查看器中遇到网格高度问题。 I am binding my grid height with the scrollviewer.我正在将我的网格高度与滚动查看器绑定。 And if I give it the fixed height then it just breaks the layout of the grid when I run the application on different devices.如果我给它固定的高度,那么当我在不同的设备上运行应用程序时,它只会破坏网格的布局。 Normally, grid height should increase dynamically when I add more content to it but it is just fixed and all of the content is getting shinked.通常,当我向其中添加更多内容时,网格高度应该会动态增加,但它只是固定的并且所有内容都在缩小。

Below I have attached some part of my code.下面我附上了我的部分代码。

Here is the image where the height is binded with the scrollviewer这是高度与滚动查看器绑定的图像

In this image, I gave a fixed height 400 and it shows what I want在这张图片中,我给出了一个固定的高度 400,它显示了我想要的

This is the image of application and it just does not have the same design as in the XAML Layout这是应用程序的图像,它的设计与 XAML 布局中的设计不同

<ScrollViewer x:Name="scrollviewer" Grid.Column="4" Grid.Row="7" Grid.ColumnSpan="7" Grid.RowSpan="20" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Visible" VerticalContentAlignment="Stretch">

        <Grid x:Name="GridInputs" Height="400" VerticalAlignment="Stretch">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="0.5*"/>
                <ColumnDefinition Width="0.5*"/>
                <ColumnDefinition Width="0.4*"/>
                <ColumnDefinition Width="0.1*"/>
                <ColumnDefinition Width="0.1*"/>
                <ColumnDefinition Width="0.4*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="0.3*"/>
                <RowDefinition Height="0.1*"/>
                <RowDefinition Height="0.3*"/>
                <RowDefinition Height="0.1*"/>
                <RowDefinition Height="0.3*"/>
                <RowDefinition Height="0.1*"/>
                <RowDefinition Height="0.3*"/>
                <RowDefinition Height="0.1*"/>
                <RowDefinition Height="0.3*"/>
                <RowDefinition Height="0.1*"/>
                <RowDefinition Height="0.3*"/>
                <RowDefinition Height="0.1*"/>
                <RowDefinition Height="0.3*"/>
                <RowDefinition Height="0.1*"/>
                <RowDefinition Height="0.3*"/>
                <RowDefinition Height="0.1*"/>
                <RowDefinition Height="0.3*"/>
                <RowDefinition Height="0.1*"/>
                <RowDefinition Height="0.3*"/>
                <RowDefinition Height="0.1*"/>
                <RowDefinition Height="0.3*"/>
                <RowDefinition Height="0.1*"/>
                <RowDefinition Height="0.3*"/>
                <RowDefinition Height="0.1*"/>
                <RowDefinition Height="0.3*"/>
                <RowDefinition Height="0.1*"/>
                <RowDefinition Height="0.3*"/>
                <RowDefinition Height="0.1*"/>
                <RowDefinition Height="0.3*"/>
                <RowDefinition Height="0.1*"/>
                <RowDefinition Height="0.3*"/>
                <RowDefinition Height="0.1*"/>
                <RowDefinition Height="0.3*"/>
                <RowDefinition Height="0.1*"/>
                <RowDefinition Height="0.3*"/>
            </Grid.RowDefinitions>
            <!-- Row 1 -->
            <Border Grid.Column="0" Grid.Row="0" BorderBrush="Black" Grid.ColumnSpan="7" BorderThickness="1" CornerRadius="5"/>
            <!--<Viewbox Grid.Row="6"  Grid.Column="4" Grid.ColumnSpan="3" x:Name="vbLongest">-->
            <Grid Grid.Row="0"  Grid.Column="0" Grid.ColumnSpan="3">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="0.2*"/>
                    <ColumnDefinition Width="6*"/>
                    <ColumnDefinition Width="1*"/>
                    <ColumnDefinition Width="6*"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="0.1*"/>
                    <RowDefinition Height="2*"/>
                    <RowDefinition Height="0.1*"/>
                </Grid.RowDefinitions>
                <Viewbox Grid.Column="1" Grid.Row="1" StretchDirection="DownOnly" HorizontalAlignment="Left">
                    <!--<TextBlock TextWrapping="Wrap" Text="Ground height to AHP" FontSize="5" Foreground="Black"/>-->
                    <Label Content="Ground Height to AHP Z" FontSize="20" FontWeight="Bold" HorizontalContentAlignment="Left" />
                </Viewbox>
                <Viewbox Grid.Column="3" Grid.Row="1" StretchDirection="DownOnly">
                    <Label x:Name="GroundHeight" HorizontalAlignment="Right" Content="Ground height to AHP" FontSize="20" FontWeight="Bold" Foreground="Gray"/>
                </Viewbox>
            </Grid>
            <!--</Viewbox>-->
            <Viewbox Grid.Row="0" Grid.Column="3" Margin="2">
                <TextBlock HorizontalAlignment="Center" TextWrapping="Wrap" Text="Z" FontSize="20" Foreground="Black"/>
            </Viewbox>
            <Viewbox Grid.Row="0" Grid.Column="4" Margin="2">
                <TextBlock HorizontalAlignment="Center" TextWrapping="Wrap" Text="=" FontSize="20" Foreground="Black"/>
            </Viewbox>
            <TextBox x:Name="tbGroundZ" Grid.Column="5" Grid.Row="0" Margin="2" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Text="{Binding CurrentPackage[BuckHeightZ].Value, Mode=TwoWay, UpdateSourceTrigger=LostFocus}"
                         FontSize="{Binding Path=ActualHeight, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Grid}, Converter={StaticResource fontSizeCon}}"/>
</Grid>

Adding viewbox after scrollviewer and moving all of the grid into the viewbox, solved my issue.在滚动查看器之后添加视图框并将所有网格移动到视图框中,解决了我的问题。 Now, I can give any fixed height and width to my grid and it does not break the design.现在,我可以为网格提供任何固定的高度和宽度,并且不会破坏设计。

Viewbox stretch and scale the child elements according to the display resolution or dimensions. Viewbox 根据显示分辨率或尺寸拉伸和缩放子元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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