开发者

Silverlight: making a grid cell always visible, even during scrolling

I 开发者_JAVA百科have a page (telerik:RadPage) containing few grids and some nested controls and I was wondering how I can:

have a particular cell in one of the grid make always visible even during scrolling. I am not even sure if it is possible, but the one cell I want visible is the first one I am displaying.

Any help is appreciated and all suggestions are welcome.

Thanks!


I have no experience working with Rad controls, but if you want to have something that's not scrollable - move it out of the ScrollViewer. This is general principle.

I give here three possible approaches, with increasing complexity, but I hope they help you at least get going.

1. Duplicate first element and show it above 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>

This method has a loot of drawbacks. Starting from duplication itself and ending with focus/keyboard management.

2. All except first elements goes into the list. First element is a separate control:

<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. Write custom control.

I don't mention Adorners here, because they seems like advanced version of approach #1. Although combined with the last approach they may result in quite good solution...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜