【问题标题】:StackPanel not scrolling in Windows Phone 8.1StackPanel 在 Windows Phone 8.1 中不滚动
【发布时间】:2014-12-09 09:01:52
【问题描述】:

我正在为 Windows Phone 8.1 构建自定义控件。但是堆栈面板没有向下滚动。 StackPanel 包含一个显示 TextBlock 的 ListView 和另一个包含 Toggle Button 的 StackPanel。

<StackPanel Orientation="Vertical" >
        <ListView Grid.Row="0" Background="RoyalBlue">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <TextBlock Text="Some Text" Foreground="Black" FontSize="20" TextAlignment="Center" ></TextBlock>
                    </Grid>                     
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
        <StackPanel Grid.Row="2" HorizontalAlignment="Stretch" Background="Red" Orientation="Horizontal">
            <Grid HorizontalAlignment="Stretch">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"></ColumnDefinition>
                </Grid.ColumnDefinitions>
                <ToggleButton Grid.Column="0" Content="Toggle Me"  />
            </Grid>
       </StackPanel>
</StackPanel>

【问题讨论】:

  • StackPanel 不滚动 - 您应该使用 ScrollViewer。此外,您可能需要定义 ListView 的高度。

标签: xaml microsoft-metro winrt-xaml windows-phone-8.1


【解决方案1】:

Stackpanel 不提供任何滚动功能。 您可以将其包装到 ScrollViewer 中。

另外:listView 已经提供了滚动功能。

但是:stackpanel 中的 ListView 将获取您所有的操作事件。此外,Stackpanel 中的 ListView 将具有无限的高度,因此会失去其虚拟化功能。

如果您只想在 ListView 上方和/下方添加内容,可以使用其 Header/Footer 属性。

【讨论】:

    【解决方案2】:

    在 StackPanel 上添加 ScrollViewer,它将使其可滚动。

    例如:

    <ScrollViewer Margin="12">
        <StackPanel>
            <TextBlock Text="content1" FontSize="48" />
            <TextBlock Text="content1" FontSize="48" />
        </StackPanel>
    </ScrollViewer>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-09
      • 1970-01-01
      • 1970-01-01
      • 2016-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多