我的 MainPage.xaml 中有一个全景控件,我希望用户能够通过使用 listpicker 控件来更改另一个页面(我的 SettingsPage.xaml)中的背景 png 图像。我已经成功地用几个测试图像名称填充了列表选择器,并且可以使用它来更改选择,但是我不确定如何从我的 SettingsPage.xaml 访问 MainPage.xaml 以在 Listpicker selectedIndex 时更改实际图像被改变。到目前为止,我所拥有的如下:
主页.xaml
<controls:Panorama x:Name="panorama" Title="Application Title">
<controls:Panorama.Background>
<ImageBrush ImageSource="PanoramaBackground.png"/> //the default background
</controls:Panorama.Background>
...
</controls:Panorama>
设置页面.xaml
<toolkit:ListPicker x:Name="ThemeListPicker" Header="Theme" Grid.Row="2" Grid.ColumnSpan="2"
ItemTemplate="{Binding ThemeItemTemplate}" SelectedIndex="{Binding}"
SelectionChanged="ThemeListPicker_SelectionChanged"/>
SettingsPage.xaml.cs
String[] Theme =
{
"Default",
"Bubbles",
//...
};
public SettingsPage()
{
InitializeComponent();
//Theme list picker
this.ThemeListPicker.ItemsSource = Theme;
this.ThemeListPicker.DataContext = ThemeListPicker.SelectedIndex;
}
private void ThemeListPicker_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems.Count <= 0) //to eliminate IndexOutOfRangeException
{
return;
}
string selectedItem = e.AddedItems[0] as string;
switch(selectedItem)
{
case "Default":
//change panorama background here (PanoramaBackground.png)
this.ThemeListPicker.SelectedIndex = 0;
break;
case "Bubbles":
//change panorama background here (PanoramaBackground_Bubbles.png)
this.ThemeListPicker.SelectedIndex = 1;
break;
}
}