Wpf 同一.xaml Grid.Row中的两个组件。当我向下滚动时,其中一个浮动,另一个滚动。我需要两者都滚动
我遇到了一些需要修复的.xaml代码。目前,它由2个网格组件组成,布局如下:Wpf 同一.xaml Grid.Row中的两个组件。当我向下滚动时,其中一个浮动,另一个滚动。我需要两者都滚动,wpf,xaml,grid-layout,Wpf,Xaml,Grid Layout,我遇到了一些需要修复的.xaml代码。目前,它由2个网格组件组成,布局如下: <Grid d:SomeDataContext> <Grid.RowDefinitions> <RowDefinition Height="100" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <ListView Style="{St
<Grid d:SomeDataContext>
<Grid.RowDefinitions>
<RowDefinition Height="100" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<ListView Style="{StaticResource SomeListStyle}" Grid.Row="0" Margin="0,0,0,0" Grid.RowSpan="2">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical" Margin="0,0,0,80" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<mycontrol:Panel1Control />
<mycontrol:Panel2Control />
<mycontrol:Panel3Control />
<mycontrol:Panel4Control />
<mycontrol:Panel5Control />
</ListView>
<controls:HeaderControlTransparent Grid.Row="0" />
</Grid>
当有人滚动时,期望的行为应该是[header]元素从屏幕的上部消失,就像它是其他面板之一一样
Desired (not happening)
...
[Panel3]
[Panel4]
[Panel5]
Undesired (happening)
[Header]
[Panel4]
[Panel5]
当前,标题不会滚动,它只是浮动在所有内容的顶部,与屏幕的顶部对齐,同时面板滚动
有什么我应该说的吗?我想一切都井然有序。我不明白为什么一行网格滚动而另一行不滚动
我对.xaml有点陌生,所以,这可能也是我遇到麻烦的原因之一。
谢谢。因此,不妨在评论中添加一点内容,为未来读者提供一些额外的解释,显然还有一些简单的要点 在您的示例中,
网格有两行(我猜是出于其他原因),两个子元素都在同一个单元格中。由于头控件部分位于DOM中的ListView
下面,因此它在逻辑上呈现在底层ListView之上
ListView已作为控件模板中内置的ScrollViewer
来嵌套其项。但是,OP要求控件模板之外的元素与ListView中的项目一起滚动
因此,通过将ListView和Header控件以正确的顺序嵌入到它们自己的父ScrollViewer中,可以获得滚动两位内容的预期结果
e、 g.(伪文本)
将对象1漂浮在对象2的顶部,并在其他所有对象滚动时保持对象1静止。但是,
<ScrollViewer>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<object1/>
<objects2 Grid.Row="1"/>
</Grid>
</ScrollViewer>
将滚动所有子对象以保持其堆叠位置
希望这有帮助,干杯 因此,只要将ListView更改为Grid.Row=1,并禁用ListView上的垂直/水平滚动,然后将其全部放入ScrollViewer,就完成了。ScrollViewer完成了这一操作。Grid.Row=0(因此重叠)在某种程度上是有意的,所以我将其保留,标题显示在第一个面板的顶部(有足够的空间)。顺便说一句,如果你把你的评论变成一个正确的答案,我会投你一票。
<Grid>
<ScrollViewer>
<objects2/>
</ScrollViewer>
<object1/>
</Grid>
<ScrollViewer>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<object1/>
<objects2 Grid.Row="1"/>
</Grid>
</ScrollViewer>