带有ItemsControl的ScrollViewer无法正常工作

时间:2012-11-07 16:08:34

标签: wpf

<ScrollViewer VerticalScrollBarVisibility="Visible"  Height="100">
        <ItemsControl Name="icReviews" BorderBrush="Black" BorderThickness="1" Height="300">
            <ItemsControl.Background>
                <LinearGradientBrush StartPoint="0,0" EndPoint="1,1" >
                    <GradientStop Offset="1" Color="#FFFF9900" />
                    <GradientStop Offset="0" Color="#FFDD4400" />
                </LinearGradientBrush>
            </ItemsControl.Background>

            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <UniformGrid Columns="3" Width="1712" Height="300"></UniformGrid>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>


            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <StackPanel>
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition ></RowDefinition>
                                <RowDefinition></RowDefinition>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"></ColumnDefinition>
                                <ColumnDefinition></ColumnDefinition>
                            </Grid.ColumnDefinitions>
                            <StackPanel Grid.Row="0" Grid.Column="1" TextElement.FontFamily="FangSong" TextElement.FontSize="15"  TextElement.FontWeight="Bold" TextElement.Foreground="Blue">
                                <TextBlock Text="{Binding Path=Subject}" Foreground="White" TextElement.FontSize="15" TextElement.FontFamily="FangSong" TextWrapping="Wrap" Margin="5,5"></TextBlock>
                                <TextBlock Text="{Binding Path=Review}" Foreground="White" TextElement.FontSize="15" TextElement.FontFamily="FangSong" TextWrapping="Wrap" Margin="5,5"></TextBlock>
                                <WrapPanel>
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Text="Posted by : " Foreground="White" Margin="5,5" TextElement.FontSize="15"></TextBlock>
                                        <TextBlock Text="{Binding Path=Username}" Foreground="White" TextElement.FontSize="15" TextElement.FontFamily="FangSong" Margin="5,5"></TextBlock>
                                    </StackPanel>
                                </WrapPanel>
                            </StackPanel>
                        </Grid>
                    </StackPanel>
                </DataTemplate>
            </ItemsControl.ItemTemplate>

        </ItemsControl>
    </ScrollViewer>

我现在用scrollviewer的height属性编辑了我的代码。我仍然无法看到任何滚动条

2 个答案:

答案 0 :(得分:4)

您是否给了ScrollViewer一个高度,或将其限制在限制其子女身高的面板内?

如果高度不受某种限制,则ScrollViewer没有理由显示滚动条,因为它可以增长到显示其子项所需的任何高度。

您可以通过将VerticalScrollBarVisibilityHorizontalScrollBarVisibility设置为Visible来测试它,以查看ScrollViewer实际所在的位置,如果是这种情况,那么您可以修复通过将ScrollViewer.Height设置为值,或将其包装在不允许其子项增长到任何所需大小的容器中来解决问题。

答案 1 :(得分:0)

您必须为包含ControlTemplate的{​​{1}}定义ItemsPresenter。我不认为它默认包含一个......