网格中网格周围的 WPF Xaml 滚动查看器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28027497/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WPF Xaml scrollviewer around Grid in Grid
提问by Matthias Roekoe
I have a Grid inside a Grid
我在网格中有一个网格
<Grid Style="{StaticResource GridMinWidthEditStyle}" Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Path=ActualWidth}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="xxx" Style="xxx"/>
<ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" PanningMode="VerticalOnly">
<Grid Background="{StaticResource LightBackground}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
</Grid>
</ScrollViewer>
</Grid>
I set my scrollviewer around the inner Grid, but i want it around the outer grid. the problem is that my vertical scrollbar is over my content at the side, and a horizontal scrollbar is added too.
我将滚动查看器设置在内部网格周围,但我希望它在外部网格周围。问题是我的垂直滚动条在我的内容上方,并且还添加了一个水平滚动条。
回答by Matthias Roekoe
Scrollbar comes over my content again at the right
滚动条在右侧再次出现在我的内容上
, but I have found a solution that works foe the rest.
,但我找到了一个对其余部分有效的解决方案。
The Scrollviewer and outer grid needs the width property instead of the outer grid. The outer Grid needs the Style (MinWidth)
Scrollviewer 和外部网格需要 width 属性而不是外部网格。外部 Grid 需要样式 (MinWidth)
<ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" PanningMode="VerticalOnly"
Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Path=ActualWidth}">
<Grid Style="{StaticResource GridMinWidthEditStyle}" Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Path=ActualWidth}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="xxx" Style="xxx"/>
<Grid Background="{StaticResource LightBackground}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
</Grid>
</Grid>
</ScrollViewer>

