gpt4 book ai didi

c# - WPF ScrollViewer 调整大小的问题

转载 作者:太空宇宙 更新时间:2023-11-03 21:11:01 24 4
gpt4 key购买 nike

我对 WPF 中的 ScrollViewer 有疑问。

当 Window 的大小缩小到 ScrollViewer 应该开始接管的位置时,窗口不会调整包含的网格的大小,滚动条的底部就会消失。

我试过将它的高度绑定(bind)到包含网格的高度,但没有成功。

这是我的 xaml:

 <Grid x:Name="MainGrid" Width="Auto" Height ="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<StackPanel Height="134" Width="Auto" VerticalAlignment="Top" Background="Blue" HorizontalAlignment="Stretch">
<Label x:Name="ProjectNumberLabel" Content="ProjectNumber" HorizontalAlignment="Left" Height="45.5" VerticalAlignment="Top" Width="350" FontSize="32" Margin="10,0,0,0" Foreground="White"/>

<Label x:Name="ProjectNameLabel" Content="ProjectName" HorizontalAlignment="Stretch" Height="42" VerticalAlignment="Top" FontSize="24" Margin="10,0,0,0" Foreground="White" Width="auto"/>

<Label x:Name="SetLabel" Content="Set Id" HorizontalAlignment="Stretch" Width="Auto" Height="42" Margin="10,0,10,0" FontSize="24" VerticalAlignment="Top" Foreground="White" />

</StackPanel>

<ScrollViewer HorizontalAlignment="Stretch" Margin="0,140,0,0" Width="Auto" CanContentScroll="True" Height="{Binding ElementName=MainGrid, Path=ActualHeight }">
<StackPanel Name="ContainingPanel" VerticalAlignment="Top" HorizontalAlignment="Stretch" Width="Auto" Height="Auto">
<StackPanel HorizontalAlignment="Stretch" Width="Auto" Height="300"/>

<StackPanel HorizontalAlignment="Stretch" Height="38" VerticalAlignment="Bottom">
<CheckBox x:Name="ComplexDataCheckBox" Content="Show All Data" Click="ComplexDataCheckBox_Click" RenderTransformOrigin="1.751,0.547" Margin="0,4,0,0" Height="16" HorizontalAlignment="Right" Width="105" VerticalAlignment="Bottom">
<CheckBox.LayoutTransform>
<ScaleTransform ScaleX="2" ScaleY="2" />
</CheckBox.LayoutTransform>
</CheckBox>
</StackPanel>

<StackPanel HorizontalAlignment="Stretch">
<syncfusion:SfDataGrid HorizontalAlignment="Stretch" Width="Auto" VerticalAlignment="Stretch" x:Name="SpecimenGrid" AutoGenerateColumns="True" RowStyleSelector="{StaticResource styleselector}"/>
</StackPanel>

</StackPanel>
</ScrollViewer>
</Grid>

最佳答案

如果 ScrollViewer 的高度等于网格高度并且垂直边距不是零,它会超出网格边界。

最好把StackPanel和ScrollViewer放在两个独立的Grid Rows中:

<Grid x:Name="MainGrid">
<Grid.RowDefinitions>
<RowDefinition Height="140"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<StackPanel Grid.Row="0">
<!--Content-->
</StackPanel>

<ScrollViewer Grid.Row="1"
HorizontalAlignment="Stretch"
Margin="0"
CanContentScroll="True" >
<!--Content-->
</ScrollViewer>
</Grid>

关于c# - WPF ScrollViewer 调整大小的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37615155/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com