Silverlight:即使在滚动期间,网格单元也始终可见

时间:2010-03-12 18:03:06

标签: wpf silverlight

我有一个包含几个网格和一些嵌套控件的页面(telerik:RadPage),我想知道如何:

即使在滚动期间,其中一个网格中的特定单元格始终可见。我甚至不确定它是否可能,但我想要的一个单元格是我正在显示的第一个单元格。

欢迎任何帮助,欢迎提出所有建议。

谢谢!

1 个答案:

答案 0 :(得分:0)

我没有使用Rad控件的经验,但是如果你想要一些不可滚动的东西 - 将它移出ScrollViewer。这是一般原则。

我在这里给出了三种可能的方法,越来越复杂,但我希望它们能帮助你至少开始。

1。复制第一个元素并将其显示在ScrollViewer上方:

<Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <Grid>  
    <ListBox>
      <TextBlock Text="First element"/>
      <TextBlock Text="Second element"/>
      <TextBlock Text="Third element"/>
      <TextBlock Text="Forth element"/>
      <TextBlock Text="Fifth element"/>
    </ListBox>    
    <!-- Overlay -->
    <Border Background="White" VerticalAlignment="Top">
      <TextBlock Text="Overlay text. Should be a duplicate of the First Element"
                 Margin="3, 0"/>
    </Border>
  </Grid>
</Page>

这种方法有一些缺点。从复制本身开始,以焦点/键盘管理结束。

2. 除第一个元素外的所有元素都会进入列表。第一个元素是一个单独的控件:

<Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <Grid>  
    <Grid.RowDefinitions>
     <RowDefinition Height="Auto"/>
     <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <!-- First Element -->
    <TextBlock Text="First element"
               Grid.Row="0"
               Margin="4, 0"/>

    <!-- List Element -->
    <ListBox Grid.Row="1" BorderThickness="0">
      <TextBlock Text="Second element"/>
      <TextBlock Text="Third element"/>
      <TextBlock Text="Forth element"/>
      <TextBlock Text="Fifth element"/>
    </ListBox>    
  </Grid>
</Page>

3. 编写自定义控件。

我在这里没有提及Adorners,因为它们看起来像方法#1的高级版本。虽然结合最后一种方法,但它们可能会产生相当好的解决方案......