MainPage.xaml にパノラマ コントロールがあり、リストピッカー コントロールを使用して、ユーザーが別のページである SettingsPage.xaml の背景の png 画像を変更できるようにしたいと考えています。リストピッカーにいくつかのテスト画像名を正常に入力し、それを使用して選択を変更できますが、SettingsPage.xaml から MainPage.xaml にアクセスして実際の画像を変更する方法がわかりません Listpicker selectedIndex変更されます。これまでのところ、私が持っているものは次のとおりです。
MainPage.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;
}
}