简体   繁体   English

将数据从一个列表框的项目源移动到另一列表框WP8

[英]Move data from itemsource of one listbox to another listbox wp8

I am parsing a RSS Feed from one site and storing it in listbox1 and then parsing another RSS storing it in listbox2 . 我正在解析来自一个站点的RSS Feed,并将其存储在listbox1 ,然后解析另一个RSS将其存储在listbox2 Now I want to combine the data of listbox1 and listbox2 in listbox3 . 现在,我想在listbox2listbox3 listbox1listbox2的数据。 It might sound silly but I am unable to do it. 听起来可能很傻,但是我做不到。 The main problem is I am not able to access the controls inside the listbox. 主要问题是我无法访问列表框内的控件。

<ListBox x:Name="list1" ItemsSource="{Binding RSSData}" DataContext="{Binding RSSData}" Visibility="Collapsed">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel>
                <TextBlock HorizontalAlignment="Center"  x:Name="txtpubDate" Foreground="#FF170505"  Text="{Binding Path=pubDate}" TextDecorations="Underline" ></TextBlock>
                <TextBlock Padding="18" Foreground="#FF0E0101" x:Name="txtTitle"  TextWrapping="Wrap" Text="{Binding Path=Title}" FontWeight="Bold"></TextBlock>
                <Image Height="200"  x:Name="imageLink"   Source="{Binding strImg}"></Image>
                <TextBlock Foreground="#FF0F0202" Padding="35" TextTrimming="WordEllipsis" HorizontalAlignment="Left" x:Name="txtDesc" Margin="2"  TextWrapping="Wrap" Text="{Binding Path=Description,Converter={StaticResource RssTextTrimmer}}"></TextBlock>
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

This is the XAML code of my listbox1 and I am trying to do it with listbox3.itemsource=listbox1.itemsource; 这是我的listbox1的XAML代码,我正在尝试使用listbox3.itemsource=listbox1.itemsource; but nothing is happening. 但是什么也没发生。

I also tried to add data in this way: listbox3.items.add(listbox.items[i]) but nothing is working. 我也尝试过以这种方式添加数据: listbox3.items.add(listbox.items[i])但没有任何效果。

Please help. 请帮忙。

You can loop through the contents of the listbox and add them one by one for instance: 您可以遍历列表框的内容,然后将它们一一添加:

foreach(object item in listbox1.items)
{
   listbox3.items.add(item);
}

and then do the same for listbox2. 然后对listbox2执行相同的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM