一个ScrollViewer用于两个ListBox

时间:2012-07-13 11:20:57

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

我有2个列表框和一个scrollviewer,我希望scrollviewer将两个列表框一起滚动。但我不知道该怎么做..这是我的xaml:

        <ScrollViewer Grid.Row="1">
        <Grid>
            <ListBox Name="listboxRSSFeedItems" Width="240" Height="644" Margin="0,0,240,0">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <TextBlock TextWrapping="Wrap" Text="{Binding Title}" Grid.Row="0" FontSize="24" HorizontalAlignment="Left" />
                            <HyperlinkButton Content="Link to details" NavigateUri="{Binding Link}" HorizontalAlignment="Left" Grid.Row="1" Margin="0,0,0,30" />
                        </Grid>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
            <ListBox Name="listboxRSSFeedItems2" Width="240" Height="644" Margin="240,0,0,0">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <TextBlock TextWrapping="Wrap" Text="{Binding Title}" Grid.Row="0" FontSize="24" HorizontalAlignment="Left" />
                            <HyperlinkButton Content="Link to details" NavigateUri="{Binding Link}" HorizontalAlignment="Left" Grid.Row="1" Margin="0,0,0,30" />
                        </Grid>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </Grid>
    </ScrollViewer>

非常感谢


确定。我只是尝试用网格做一个列表框。它工作正常,但如何选择添加我的项目的网格。 我曾经添加“listboxRSSFeedItems.Items.Add(item)”,但现在,我如何才能选择第二列。

   <ScrollViewer Grid.Row="1">
        <ListBox x:Name="listboxRSSFeedItems" Width="480" Height="680">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <Grid x:Name="first" Grid.Column="0"> 
                            <TextBlock TextWrapping="Wrap" Text="{Binding Title}" />
                            <HyperlinkButton NavigateUri="{Binding URL}" TargetName="_blank"/>
                        </Grid>
                        <Grid x:Name="second" Grid.Column="1">
                            <TextBlock TextWrapping="Wrap" Text="{Binding Title}" />
                            <HyperlinkButton NavigateUri="{Binding URL}" TargetName="_blank" />
                        </Grid>
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </ScrollViewer>

再次感谢

2 个答案:

答案 0 :(得分:0)

您不应设置listBox的高度。

ps:使用列

考虑布局
    <ScrollViewer >
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <ListBox x:Name="first" Grid.Column="0" />

            <ListBox x:Name="second" Grid.Column="1" />
        </Grid>
    </ScrollViewer>

答案 1 :(得分:0)

为listBoxes将VerticalScrollBarVisibility设置为“已禁用”。 最好使用StackPanel来表示此puprose,而不是Grid