我有一个ContentControl
,其中包含DataGrid
- 全部都在ScrollViewer
内。我需要DataGrid
滚动ScrollViewer
而不是自己滚动。目前当DataGrid
大于ScrollViewer
垂直滚动条出现时,但它超出了底部边框 - 我添加了一张图片来显示这一点。如何让Scrollbar
停在ScrollViewer
的底部? XAML:
<ScrollViewer Name="scvDG" Style="{StaticResource scrBarV}" Margin="24,217,22,0"
VerticalScrollBarVisibility="Auto" Height="526" VerticalAlignment="Top"
BorderBrush="Transparent" Foreground="Transparent"
BorderThickness="0" MaxHeight="526">
<ContentControl Width="756" Height="Auto" VerticalAlignment="Top" HorizontalAlignment="Left">
<sdk:DataGrid x:Name="dgStaff" Margin="0,4" Width="756" HorizontalAlignment="Left"
AutoGenerateColumns="False" Background="#FFB7ADE5" Style="{StaticResource dg}"
Visibility="Visible" VerticalAlignment="Top" Height="Auto"
HorizontalContentAlignment="Left" VerticalContentAlignment="Top">
<sdk:DataGrid.Columns>
...
</sdk:DataGrid.Columns>
</sdk:DataGrid>
</ContentControl>
</ScrollViewer>
如果您还需要其他信息,请告诉我。
答案 0 :(得分:1)
最好删除内容控件,因为它占用了网格,
这有效
<Grid x:Name="LayoutRoot" Background="White">
<ScrollViewer Name="scvDG" Margin="34,105,12,0"
VerticalScrollBarVisibility="Auto" Height="195" VerticalAlignment="Top"
BorderBrush="Transparent" Foreground="Transparent"
BorderThickness="0" MaxHeight="526">
<sdk:DataGrid x:Name="dgStaff" Margin="0,4" Width="756" HorizontalAlignment="Left"
AutoGenerateColumns="False" Background="#FFB7ADE5"
Visibility="Visible" VerticalAlignment="Top" Height="600"
HorizontalContentAlignment="Left" VerticalContentAlignment="Top">
</sdk:DataGrid>
</ScrollViewer>
答案 1 :(得分:0)
我没有意识到它会覆盖滚动查看器,但确实如此。这是那个有趣的有趣滚动条的样式。查看RowDefinition
部分。
<Style x:Key="scrBarV" TargetType="ScrollViewer">
<Setter Property="HorizontalContentAlignment" Value="Right" />
<Setter Property="VerticalContentAlignment" Value="Top" />
<Setter Property="VerticalScrollBarVisibility" Value="Visible" />
<Setter Property="Padding" Value="4" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="BorderBrush">
<Setter.Value>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFA3AEB9" Offset="0" />
<GradientStop Color="#FF8399A9" Offset="0.375" />
<GradientStop Color="#FF718597" Offset="0.375" />
<GradientStop Color="#FF617584" Offset="1" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ScrollViewer">
<Border CornerRadius="2" BorderBrush="{StaticResource hdrLGB}" BorderThickness="2">
<Grid>
<Grid.RowDefinitions>
<!--<RowDefinition Height="665" WRONG />-->
<RowDefinition Height="*" /> <!--<RIGHT />-->
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ScrollContentPresenter x:Name="ScrollContentPresenter"
Cursor="{TemplateBinding Cursor}"
Margin="{TemplateBinding Padding}"
ContentTemplate="{TemplateBinding ContentTemplate}" />
<Rectangle Grid.Column="1" Grid.Row="0" Fill="#FFE9EEF4" />
<ScrollBar x:Name="VerticalScrollBar" Width="50" IsTabStop="False"
Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"
Grid.Column="1" Grid.Row="0" Orientation="Vertical"
ViewportSize="{TemplateBinding ViewportHeight}"
Maximum="{TemplateBinding ScrollableHeight}" Minimum="0"
Value="{TemplateBinding VerticalOffset}" Margin="0,-1,-1,-1" />
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
感谢您的帮助!