WP7项目将显示在循环选择器中

时间:2012-08-11 11:16:10

标签: windows-phone-7

我正在使用循环选择器来显示标志,这些标志以经典方式加载到列表中,如下所示:

public MainPage()
{
    InitializeComponent();

    List<DataContinent> data = new List<DataContinent>(); 
    data.Add(new DataContinent() { Flag = new Uri("/Images/Albania.png", UriKind.Relative).ToString() });
    data.Add(new DataContinent() { Flag = new Uri("/Images/Andorra.png", UriKind.Relative).ToString() });
    ...
    ...
    this.loopingSelectorContinent.DataSource = new ListLoopingDataSource<DataContinent>() {Items = data, SelectedItem = data[0]};
}

是否可以在运行时根据所选的大陆在循环选择器中加载不同的图像,或者作为替代方案,可以阻止某些项的循环?

1 个答案:

答案 0 :(得分:0)

我找到了一种简单的方法来解决我将要描述的问题,因为它可能对其他人有用。 基本上,不是在Main内部初始化循环选择器,而是可以在外部完成,之后在必要时调用适当的函数。 这是一个例子:

public MainPage()
{
    InitializeComponent();
    Europe(); //standard visualization
}

public void Europe()
{
    List<DataContinent> data = new List<DataContinent>(); 
    data.Add(new DataContinent() { Flag = new Uri("/Images/Albania.png", UriKind.Relative).ToString() });
    data.Add(new DataContinent() { Flag = new Uri("/Images/Andorra.png", UriKind.Relative).ToString() });
    ...
    ...
    this.loopingSelectorContinent.DataSource = new ListLoopingDataSource<DataContinent>() {Items = data, SelectedItem = data[0]};
}
public void Africa()
{
    List<DataContinent> data = new List<DataContinent>(); 
    data.Add(new DataContinent() { Flag = new Uri("/Images/Algeria.png", UriKind.Relative).ToString() });
    data.Add(new DataContinent() { Flag = new Uri("/Images/Angola.png", UriKind.Relative).ToString() });
    ...
    ...
    this.loopingSelectorContinent.DataSource = new ListLoopingDataSource<DataContinent>() {Items = data, SelectedItem = data[0]};
}

private void button1_Click(object sender, RoutedEventArgs e) //loopingselector populated with European flags
{
Europe();
}

private void button2_Click(object sender, RoutedEventArgs e) //loopingselector populated with African flags
{
Africa();
}