更新的背景圖像我在MainPage.xaml中全景控制,我想用戶能夠改變的背景中另一個頁面png圖片,我SettingsPage.xaml,通過使用一個listpicker控件。我已經成功地填充listpicker用幾個測試圖像的名字,我能夠用它來改變選擇,但我不確定如何從我的SettingsPage.xaml訪問MainPage.xaml中改變實際的圖像時,Listpicker的selectedIndex被改變。到目前爲止,我有什麼是folows:如何從另一頁WP7
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>
SettingsPage.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;
}
}
好吧,如果我這樣做,我想我的問題是什麼是創造的URI,然後設置的正確方法該URI等於全景背景(假設我添加'X:名稱=「panBackgroundImage」'作爲圖像刷名) – Matthew 2012-07-13 07:45:51
變種名稱=(Application.Current如APP).YourString; BitmapImage image = new BitmapImage(new Uri(name,UriKind.Relative)); ImageBrush brush = new ImageBrush(); brush.ImageSource = image; panorama.Background = brush; 當然,這是以防萬一你的形象(「PanoramaBackground_Bubbles.png」爲例)是在項目的根目錄下。如果不是,則需要將文件夾名稱添加到字符串YourString(例如「/ Images /」+ name) – 2012-07-13 07:56:01