我找到了一种解决我将要描述的问题的简单方法,因为它可能对其他人有用。基本上,与其在 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();
}