Windows Phone ListPicker传递SelectedItem

时间:2013-01-25 12:09:56

标签: c# windows-phone-7 rss selecteditem listpicker

我正在使用rss reader sample和listPicker。我想要做的是将rss url从listPicker项传递给webClient.DownloadStringAsync。

**MainPage.xaml**
[...]
<toolkit:ListPicker.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding Nazwa}"
                                   Margin="12 0 0 0"
                                   VerticalAlignment="Center"/>
                        <Image Source="/Repertuar;component/Images/open.png" FlowDirection="RightToLeft" />
                    </StackPanel>
                </DataTemplate>
            </toolkit:ListPicker.ItemTemplate>
            <toolkit:ListPicker.FullModeItemTemplate>
                <DataTemplate>
                    <StackPanel Margin="16 21 0 20">
                        <TextBlock Text="{Binding Nazwa}"
                                   FontSize="43"/>
                    </StackPanel>
                </DataTemplate>
            </toolkit:ListPicker.FullModeItemTemplate>
[...]

**MainPage.xaml.cs**
[...]
public class Miasto
{
    public string Nazwa
    {
        get;
        set;
    }

    public string Adres
    {
        get;
        set;
    }
}

public partial class MainPage : PhoneApplicationPage
{
    // Constructor
    public MainPage()
    {
        InitializeComponent();
        IEnumerable<Miasto> source = this.GetDataSource();
        this.listPicker.ItemsSource = source;
    }
    private IEnumerable<Miasto> GetDataSource()
    {
        List<Miasto> source = new List<Miasto>();
        source.Add(new Miasto() { Nazwa = "Bydgoszcz", Adres = "http://film.wp.pl/rss.xml?id=10" });
        source.Add(new Miasto() { Nazwa = "Gdańsk", Adres = "http://film.wp.pl/rss.xml?id=27" });
        return source;
    }
[...]
    webClient.DownloadStringAsync(new System.Uri("http://film.wp.pl/rss.xml?id=27"));
[...]

我不知道如何解决这个问题。这个问题有一个简单的解决方案吗?

1 个答案:

答案 0 :(得分:0)

您可以将ID传递给选择更改事件的网址。您是否尝试在列表项上预加载信息?