【问题标题】:Change height of a listbox as when the scrollviewer is scrolled滚动滚动查看器时更改列表框的高度
【发布时间】:2015-03-04 09:02:20
【问题描述】:

我在滚动查看器中有一个列表框,我想在向上/向下滚动时更改列表框的高度。当我向下滚动时,列表框的高度应该增加,反之亦然

这是我的做法:

private void OnScrollbarValueChanged(object sender,RoutedPropertyChangedEventArgs<double> e)
    {
        listbox.Height += e.NewValue - e.OldValue;       
    }

然而,这符合我的目的,但似乎落后了很多。当我滚动和高度变化时,有很多口吃。无论如何要摆脱口吃/滞后,让这种高度变化无滞后?

【问题讨论】:

  • 你是不是想实现类似视差的效果?
  • 我认为你可以通过使用 Storyboard 和 DoubleAnimation 来实现平滑。
  • @SeeSharp - 确实如此!虽然,视差效果已经集成,没有口吃,但现在的困难是在页面底部有一个文本框,即使键盘出现,它也应该始终保留在那里。并操纵列表框的高度。视差在 ListBox 的顶部,其中有一个图像。

标签: c# silverlight windows-phone-8 listbox scrollviewer


【解决方案1】:

于是我找到了一个example如何在windows phone中实现视差效果,并稍作修改。

这是 XML,我认为这正是您想要的。

<Grid x:Name="LayoutRoot"
      Background="Transparent">
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
        <RowDefinition Height="30"/>
    </Grid.RowDefinitions>
    <Grid Grid.Row="0">
        <Grid x:Name="ImageContainer"
          VerticalAlignment="Top"
          CacheMode="BitmapCache"
          RenderTransformOrigin="0.5,0.5">
            <Grid.RenderTransform>
                <CompositeTransform x:Name="ImageTransform" />
            </Grid.RenderTransform>
            <Image Source="/Assets/chitanda.jpg"
               Stretch="None"
               HorizontalAlignment="Center"
               VerticalAlignment="Top"
               x:Name="Image" />
        </Grid>
        <ScrollViewer x:Name="Scroller" Margin="0,300,0,0"
                  ManipulationMode="Control"
                  Background="#33000000">
            <Grid x:Name="ScrollGrid" Margin="0,-300,0,0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="500" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <StackPanel x:Name="TitlePanel"
                        VerticalAlignment="Bottom"
                        Margin="0,0,0,24">
                    <TextBlock Style="{StaticResource PhoneTextTitle1Style}"
                           Margin="24,0"
                           TextWrapping="Wrap"
                           Text="Title" />
                </StackPanel>
                <ListBox x:Name="ListBox1" Grid.Row="1" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding}"/>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </Grid>
        </ScrollViewer>
    </Grid>
    <Grid Grid.Row="1">
        <TextBlock Text="Static TextBox on the bottom" HorizontalAlignment="Center"/>
    </Grid>
</Grid>

为了避免滚动冲突,我在 ListBox 中禁用了它。代码隐藏是完全一样的。我希望这就是你要找的。快乐编码(:

【讨论】:

  • 感谢您的努力,但我不是在寻找这种行为,我也找到了相同的博客,但我已根据自己的需要修改了 xaml
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-20
  • 2018-11-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多