Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Silverlight:使用ScrollViewer有困难_Silverlight_Windows Phone 7 - Fatal编程技术网

Silverlight:使用ScrollViewer有困难

Silverlight:使用ScrollViewer有困难,silverlight,windows-phone-7,Silverlight,Windows Phone 7,我正在制作wp7 Silverlight应用程序。我有一个ScrollViewer,它包含一个由十个元素组成的ListBox。然而,它只允许我向下滚动一点点。我可能做错了什么 <ScrollViewer> <ListBox x:Name="StoryListBox"/> </ScrollViewer> 我在这里做错了什么?我不明白为什么需要将列表框嵌入ScrollViewer中。如果列表框中的项目多于其在可视区域中显示的项目,则列表

我正在制作wp7 Silverlight应用程序。我有一个
ScrollViewer
,它包含一个由十个元素组成的
ListBox
。然而,它只允许我向下滚动一点点。我可能做错了什么

<ScrollViewer>
        <ListBox x:Name="StoryListBox"/>
    </ScrollViewer>


我在这里做错了什么?

我不明白为什么需要将列表框嵌入ScrollViewer中。如果列表框中的项目多于其在可视区域中显示的项目,则列表框项目应自行滚动。如果使用Expression Blend编辑列表框的样式,该样式将如下所示-

<Style x:Key="ListBoxListStyle" TargetType="ListBox">
    <Setter Property="Background" Value="Transparent"/>
    <Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
    <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"/>
    <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
    <Setter Property="BorderThickness" Value="0"/>
    <Setter Property="BorderBrush" Value="Transparent"/>
    <Setter Property="Padding" Value="0"/>
    <Setter Property="Template">
        <Setter.Value>     
            <ControlTemplate TargetType="ListBox">
                <ScrollViewer 
                    x:Name="ScrollViewer" 
                    BorderBrush="{TemplateBinding BorderBrush}" 
                    BorderThickness="{TemplateBinding BorderThickness}" 
                    Background="{TemplateBinding Background}" 
                    Foreground="{TemplateBinding Foreground}" 
                    Padding="{TemplateBinding Padding}" >
                <ItemsPresenter/>
                </ScrollViewer>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>


您可以看到嵌入在列表框的ControlTemplate中的ScrollViewer,它负责ListBoxItems的滚动。

ScrollViewer只能在其小于所包含的(宽度或高度)时工作。如果不指示ScrollViewer的宽度或高度,它将被拉伸以适合其内容,因此效果将不完美

因此,您需要做的是为ScrollViewer设置一个固定的大小

顺便说一下,正如indyfromoz所说,列表框已经有了ScrollViewer,因此您可以删除外部ScrollViewer,只需设置列表框的大小。

在我设置列表框的高度后,它(滚动)工作得非常好

<Style x:Key="ListBoxListStyle" TargetType="ListBox">
    <Setter Property="Background" Value="Transparent"/>
    <Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
    <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"/>
    <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
    <Setter Property="BorderThickness" Value="0"/>
    <Setter Property="BorderBrush" Value="Transparent"/>
    <Setter Property="Padding" Value="0"/>
    <Setter Property="Template">
        <Setter.Value>     
            <ControlTemplate TargetType="ListBox">
                <ScrollViewer 
                    x:Name="ScrollViewer" 
                    BorderBrush="{TemplateBinding BorderBrush}" 
                    BorderThickness="{TemplateBinding BorderThickness}" 
                    Background="{TemplateBinding Background}" 
                    Foreground="{TemplateBinding Foreground}" 
                    Padding="{TemplateBinding Padding}" >
                <ItemsPresenter/>
                </ScrollViewer>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>