3

我有 2 个列表框和一个滚动查看器,我希望滚动查看器将两个列表框一起滚动。但我不知道该怎么做.. 这是我的 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>

再次感谢

4

2 回答 2

0

将列表框设置VerticalScrollBarVisibility为“禁用”。并且它会更好地StackPanel用于这个 puprose 而不是Grid.

于 2012-07-13T12:08:45.297 回答
0

您不应该设置列表框的高度。

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>
于 2012-07-13T11:45:39.957 回答