Reputation: 35
I'm writing a music player app for WP8 in XAML and C#, but coming from a winforms background I don't know how to do the following.
My main page opens a separate page to display the tracks of a music album. The user can select some of these tracks which then get added to a central playlist which is working fine, but I want the main page to call its playlist refresh function when the song selection page is closed.
If I was doing this as winforms I would do something like:
private void ShowAlbumPage(Int16 albumId)
{
albumPage.albumId = albumId;
albumPage.ShowDialog();
RefreshPlaylist();
}
But this will not work for XAML
I currently have this:
private void ShowAlbumPage(Int16 albumId)
{
NavigationService.Navigate(new Uri("/AlbumPage.xaml?albumId=" + albumId.ToString(), UriKind.Relative));
}
Any suggestions on how and when to call RefreshPlaylist?
Upvotes: 0
Views: 139
Reputation: 35
I think I have found a reasonably simple workaround - I have just put a call to RefreshPlayQueue() in the OnNavigatedTo method of MainPage.xaml. This seems to work
Upvotes: 0
Reputation: 8273
Its a vague idea ,but i think if i share i can also improve. You could pass the List to the AlbumPage (Current collection) , if user add a song to playlist , add this to the collection , when returning just send back the collection and update the Home Page.
// MainPage.Xaml
private void list_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
SongsList selectedItemData = SelectedItem as SongsList ;
if(selectedItemData != null)
{
NavigationService.Navigate(new Uri(string.Format("/AlbumPage.xaml?parameter={0}",selectedItemData.ID ), UriKind.Relative));
}
}
//AlbumPAge.Xaml
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
string parameter = this.NavigationContext.QueryString["parameter"];
SongsList country = null;
// GETS THE SONG COLLECTION HERE , UPDATE WHEN USER ADD TO PLAYLIST , AND RETURN BACK.
}
**If your doing on MVVM Way .This is just an Idea not tested.**
There is view-model it contains Collection of Songs, Maintain the same view-model over the two pages , Update the Song collection so Mainpage UI will automatically gets updated.
ViewModel Maintain the same over the Album Page.
ObservableCollection<Songs> _songs=new ObservableCollection<Songs>();
_songs.Add(new songs{Artist="ArtistName",Album="AlbumName"});
// AlbumPage CodeBehind.
private AddSongtoPlaylist(Song currentSong)
{
_songs.Add(currentSong);
}
Upvotes: 1
Reputation: 2060
Some of the ways you could accomplish this:
PhoneApplicationService.State
Dictionary. Whenever you return to the main page, load the transient state that will include the added songs.IsolatedStorage
and load them whenever you navigate to the main page.QueryString
.The method you choose is just a matter of personal preference.
Upvotes: 0