0

我有一个堆栈面板,它有时包含的数据多于屏幕上无法容纳的数据。发生这种情况时,我无法向下滚动查看列表的其余部分。所以我添加了一个 ScrollViewer 来解决这个问题,但我无法让它工作。这是代码:

   <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <ScrollViewer Height="500" Name="Scroller" VerticalScrollBarVisibility="Auto">
            <StackPanel Orientation="Vertical" Name="Stack" Height="2000">
                <TextBlock Text="{Binding BookableExplanation}" Foreground="#336699" TextWrapping="Wrap"/>
                <Button Visibility="{Binding ShowLinkToSite, Converter={StaticResource BooleanToVisibilityConverter}}" cal:Message.Attach="[Event Click] = [Action OpenStuntOnWebAsRegularOffer]" Foreground="#FFFFFF" Background="#336699" BorderThickness="0">neckermann.be</Button>
                <ListBox x:Name="DepartureDates" MinHeight="2000"
                        cal:Message.Attach="[Tap]=[Action OpenStuntOnWeb(DepartureDates.SelectedItem)]">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <Grid DataContext="{Binding}" Background="#336699" Margin="0,10,0,10">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" MinWidth="430"/>
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="*"/>
                                </Grid.RowDefinitions>
                                <StackPanel Grid.Column="1" Orientation="Vertical" Margin="10,10,10,10">
                                    <TextBlock Text="{Binding Date, StringFormat='dd/MM/yyyy'}" Foreground="#FFFFFF" TextWrapping="Wrap" TextAlignment="Center"/>
                                </StackPanel>
                            </Grid>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </StackPanel>
        </ScrollViewer>
    </Grid>

有任何想法吗 ?在其他视图中,我只有可以正常滚动的文本,只有在动态添加项目时才会遇到问题。在这里也看到了一些关于滚动查看器问题的帖子,但遵循了这些建议,例如将滚动查看器高度设置为低于堆栈面板,但没有奏效。这可能是一件非常简单的事情,但找不到它:) 它会进行滚动运动,但只是不允许我往下走。

谢谢,

乔恩

4

2 回答 2

0

Listbox 具有内置的滚动查看器。因此,如果您手动添加滚动查看器,两个控件将相互争斗。

请删除您的滚动查看器。将工作。

于 2013-08-07T12:32:42.123 回答
0

我设法通过修改我的 XAML 来修复它。看来堆栈面板是问题所在。现在的行为略有不同,但我可以忍受。

        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <StackPanel Grid.Row="0" Margin="0,0,0,5">
                <TextBlock Text="{Binding BookableExplanation}" Foreground="#336699" TextWrapping="Wrap"/>
                <Button Visibility="{Binding ShowLinkToSite, Converter={StaticResource BooleanToVisibilityConverter}}" cal:Message.Attach="[Event Click] = [Action OpenStuntOnWebAsRegularOffer]" Foreground="#FFFFFF" Background="#336699" BorderThickness="0">neckermann.be</Button>
            </StackPanel>
            <ListBox Grid.Row="1" x:Name="DepartureDates" 
                    cal:Message.Attach="[Tap]=[Action OpenStuntOnWeb(DepartureDates.SelectedItem)]">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid DataContext="{Binding}" Background="#336699" Margin="0,10,0,10">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" MinWidth="430"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>
                            <StackPanel Grid.Column="1" Orientation="Vertical" Margin="10,10,10,10">
                                <TextBlock Text="{Binding Date, StringFormat='dd/MM/yyyy'}" Foreground="#FFFFFF" TextWrapping="Wrap" TextAlignment="Center"/>
                            </StackPanel>
                        </Grid>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </Grid>
    </Grid>
于 2013-07-12T14:12:49.803 回答