【问题标题】:How to disable the scrollview in LongListSelector in windows phone 7如何在 windows phone 7 中禁用 LongListSelector 中的滚动视图
【发布时间】:2015-02-26 07:06:38
【问题描述】:

我想禁用 LongListSelector 中的滚动视图。

我试过这样:

<toolkit:LongListSelector x:Name="List_Contacts" 
                                      IsFlatList= "False"
                                      DisplayAllGroups="False"
                                      Margin="0,0,0,100" 
                                      Width="480" 
                                      Background="Transparent" 
                                      ItemsSource="{Binding ResultList}"
                                      ItemTemplate="{StaticResource ItemTemplate}" 
                                      GroupHeaderTemplate="{StaticResource GroupItemHeaderTemplate}"
                                              ScrollViewer.VerticalScrollBarVisibility="Disabled"
                                                  ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                                      Tap="List_Contacts_Tap"/>

但是这里的滚动没有被禁用。

我从堆栈溢出中找到了一种解决方案

<Style x:Key="LongListSelectorWithNoScrollBarStyle" TargetType="toolkit:LongListSelector">
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="phone:LongListSelector">
                        <Grid Background="{TemplateBinding Background}" d:DesignWidth="480" d:DesignHeight="800">
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="ScrollStates">
                                    <VisualStateGroup.Transitions>
                                        <VisualTransition GeneratedDuration="00:00:00.5"/>
                                    </VisualStateGroup.Transitions>
                                    <VisualState x:Name="Scrolling" />
                                    <VisualState x:Name="NotScrolling"/>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Grid Margin="{TemplateBinding Padding}">
                                <ViewportControl x:Name="ViewportControl" 
                                                 HorizontalContentAlignment="Stretch" 
                                                 VerticalAlignment="Top"/>
                            </Grid>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

但是这里我遇到了错误

找不到类型“ViewportControl”。确认您没有丢失程序集引用,并且所有引用的程序集都已构建。

我也将命名空间包含在 xaml 中。

xmlns:ViewportControl="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows"

但现在我仍然收到'ViewportControl' was not found 错误。

请帮我禁用 LLS 中的滚动。

这里所有元素都是可滚动的。LLS 将有 N 个项目。如果我将 LLS 滚动到上面的堆栈面板也应该滚动到顶部。

【问题讨论】:

  • 为什么要禁用滚动?你不能使用 IsHitTestVisible 属性吗?
  • @Pradeep.. 我也想写点击事件。所以我不能使用这个 IsHitTestVisible .. 我的要求就是这样。这就是为什么我这样问..
  • 解释为什么要禁用滚动?

标签: c# xaml windows-phone-7 longlistselector


【解决方案1】:

您可以通过将 LongListSelector(LLS) 的高度设置为大于所有项目的高度来禁用滚动。您可以为 LLS 设置最大高度以避免滚动。

在 ScrollViewer 中包含 LLS 不是一个好习惯,两个滚动条都会为它们的输入事件而战,结果不会像预期的那样。

另外,为了更专注于您的问题,您可以将 StackPanels 添加到 LLS 的 ListHeader,这样当您滚动 LLS 时,StackPanels 也会随着您的项目一起滚动。

使用 LLS 的ListHeader 的示例结构是,

  <phone:LongListSelector>
    <phone:LongListSelector.ListHeader>
        <StackPanel>
            <StackPanel Name="Panel1"></StackPanel>
            <StackPanel Name="Panel2"></StackPanel>
        </StackPanel>
    </phone:LongListSelector.ListHeader>
  </phone:LongListSelector>

【讨论】:

  • 我可以在运行时获取 LLS 项目。所以我不知道 LLS 的确切高度。
  • 您是否使用 AlphaKeyGroup 对您的项目进行分组?你有嵌套的 LLS 吗?
  • “这里所有的项目都可以滚动”是什么意思
  • 是的,我正在使用 AlphaKeyGroup。所有项目都是可滚动的意味着我将所有项目(堆栈面板 1、堆栈面板 2、LLS)放入 ScrollViewer。
  • 这就是问题所在,您不应该将 LLS 放入 Scrollviewer。您已将它们添加到 LLS 的 ListHeader 中,以便它们将作为第一个元素添加到您的 LLS 并在您滚动 LLS 时向上滚动。希望这会有所帮助!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-12
  • 2011-07-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多