在 Silverlight 中,是否可以让内部的某些元素ScrollViewer
保持可见?我的意思是,无论当前滚动位置在哪里,某些元素都应该始终可见。
以这个 XAML 为例(你可以把它放在 XamlPad 的 KaXaml 中):
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<ScrollViewer Width="250" Height="100" HorizontalScrollBarVisibility="Visible">
<StackPanel>
<Grid Width="350" Height="50">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50" />
<ColumnDefinition Width="50" />
<ColumnDefinition Width="50" />
<ColumnDefinition Width="50" />
<ColumnDefinition Width="50" />
<ColumnDefinition Width="50" />
<ColumnDefinition Width="50" />
</Grid.ColumnDefinitions>
<Button Content="1" Grid.Column="0" BorderThickness="2" Width="50" />
<Button Content="2" Grid.Column="1" BorderThickness="2" Width="50" />
<Button Content="3" Grid.Column="2" BorderThickness="2" Width="50" />
<Button Content="4" Grid.Column="3" BorderThickness="2" Width="50" />
<Button Content="5" Grid.Column="4" BorderThickness="2" Width="50" />
<Button Content="6" Grid.Column="5" BorderThickness="2" Width="50" />
<Button Content="X" Grid.Column="6" BorderThickness="2" Width="50" />
</Grid>
<Grid Width="350" Height="50">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50" />
<ColumnDefinition Width="50" />
<ColumnDefinition Width="50" />
<ColumnDefinition Width="50" />
<ColumnDefinition Width="50" />
<ColumnDefinition Width="50" />
<ColumnDefinition Width="50" />
</Grid.ColumnDefinitions>
<Button Content="1" Grid.Column="0" BorderThickness="2" Width="50" />
<Button Content="2" Grid.Column="1" BorderThickness="2" Width="50" />
<Button Content="3" Grid.Column="2" BorderThickness="2" Width="50" />
<Button Content="4" Grid.Column="3" BorderThickness="2" Width="50" />
<Button Content="5" Grid.Column="4" BorderThickness="2" Width="50" />
<Button Content="6" Grid.Column="5" BorderThickness="2" Width="50" />
<Button Content="X" Grid.Column="6" BorderThickness="2" Width="50" />
</Grid>
</StackPanel>
</ScrollViewer>
</Grid>
</Page>
无论您向左或向右滚动多少,我都希望将“X”按钮保持在视线范围内。当然,向下或向上滚动时,“X”按钮应跟随滚动。
我并不是说我的 XAML 的结构是理想的,但每一行都是一个数据绑定到不同的项目,所以每一行都是一个数据模板。我不能在滚动查看器中放置一个大网格,或者将列而不是行作为模板(至少,我认为我不能)。