无法在 ScrollViewer 顶部显示 UI 元素

问题描述 投票:0回答:1

我正在努力显示 UI 元素上方ScrollViewer。这应该是非常简单的,但事实并非如此。我希望这段代码能够工作:

<Grid>
    <Button>A</Button>
    <ScrollViewer ZoomMode="Enabled" x:Name="Scroller">
        <Viewbox>
            <Rectangle Width="200" Height="200" Fill="White"/>
        </Viewbox>
    </ScrollViewer>
    <Button>B</Button>
</Grid>

但是当我放大 ScrollViewer 时,它显示在两个按钮的顶部。

xaml uwp winui
1个回答
0
投票

请尝试为网格设置RowDefinitions并将UIElements放入不同的行中。

Xaml:

 <Grid>
 <Grid.RowDefinitions>
     <RowDefinition Height="Auto"/>
     <RowDefinition Height="*"/>
     <RowDefinition Height="Auto"/>
 </Grid.RowDefinitions>
 <Button Grid.Row="0">A</Button>
 <ScrollViewer Grid.Row="1" ZoomMode="Enabled" x:Name="Scroller">
     <Viewbox>
         <Rectangle Width="200" Height="200" Fill="White"/>
     </Viewbox>
 </ScrollViewer>
 <Button Grid.Row="2">B</Button>
 </Grid>
© www.soinside.com 2019 - 2024. All rights reserved.