0

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

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]};
}

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

4

1 回答 1

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();
}
于 2012-08-12T20:00:56.057 回答