代码之家  ›  专栏  ›  技术社区  ›  slugster Joey Cai

防止手动滚动ScrollViewer

  •  1
  • slugster Joey Cai  · 技术社区  · 13 年前

    HorizontalScrollBarVisibility VerticalScrollBarVisibility 都设置为 . 我正在以编程方式滚动ScrollViewer以响应用户滚动gridview。

    属性到 残疾人 不起作用,因为这样会将滚动偏移重置回零。

    如何锁定滚动或防止手动滚动?

    1 回复  |  直到 13 年前
        1
  •  0
  •   iCollect.it Ltd    13 年前

    通过删除手动操作的滚动条,并隐藏它们,你基本上是说你想要的东西有一个项目列表,可以从代码滚动,但不是一个列表框。。。

    结论:不要使用列表框:)

    当您自己管理滚动时,为什么不在画布中的StackPanel下创建文本框的父对象(当然是剪切矩形)。然后使用Canvas.Top/左属性来滚动它。

    属性进行测试。

    Xaml示例:

    <UserControl x:Class="SilverlightApplication1.NotAListbox"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        d:DesignHeight="300" d:DesignWidth="400">
    
        <Grid x:Name="LayoutRoot" Background="White">
            <Canvas Background="Aquamarine" HorizontalAlignment="Center" Name="canvas1" VerticalAlignment="Center" Width="200" Height="200">
                <Canvas.Clip>
                    <RectangleGeometry Rect="0,0,200,200"></RectangleGeometry>
                </Canvas.Clip>
                <StackPanel Canvas.Top="{Binding ElementName=slider1, Path=Value}" Name="stackPanel1">
                    <TextBox Height="23" Text="textBox 1" Width="120" />
                    <TextBox Height="23" Text="textBox 2" Width="120" />
                    <TextBox Height="23" Text="textBox 3" Width="120" />
                    <TextBox Height="23" Text="textBox 4" Width="120" />
                    <TextBox Height="23" Text="textBox 5" Width="120" />
                    <TextBox Height="23" Text="textBox 6" Width="120" />
                    <TextBox Height="23" Text="textBox 7" Width="120" />
                    <TextBox Height="23" Text="textBox 8" Width="120" />
                    <TextBox Height="23" Text="textBox 9" Width="120" />
                </StackPanel>
            </Canvas>
            <Slider Height="171" HorizontalAlignment="Center" Margin="316,62,57,66" Name="slider1" VerticalAlignment="Center" Width="27" Orientation="Vertical" Minimum="-223" Maximum="200" />
        </Grid>
    </UserControl>