I want to play songs in my windows-store app.
the thing is, I want to "share" the MediaElement
between pages because playing the sound should not stop when navigating to an other page. I am using the newest Caliburn.Micro WinRT port.
My first approach to this problem was to have the MediaElement
on the DefaultView
where i have a grid with 2 rows.
2nd row contains the MediaElement
(and all the controls that handle play, pause and so on) and 1st row is another frame
where I want to inject the actual content.
For that to work, I needed some hacking. I created a new interface
public interface INavigationService2 : INavigationService { }
and my own NavigationService as
public class NavigationService : FrameAdapter, INavigationService2
{
public NavigationService(Frame frame, bool treatViewAsLoaded = false)
: base(frame, treatViewAsLoaded) { }
}
now, I registered that with CM
public sealed partial class MainView
{
public MainView()
{
this.InitializeComponent();
MainView.InitializeComponentStatic(this);
}
private static bool _isInitialized;
private static void InitializeComponentStatic(MainView mainView)
{
if (_isInitialized) return;
((App)Application.Current).RegisterInstance(typeof(INavigationService2),
null, new NavigationService(mainView.ContentFrame));
_isInitialized = true;
}
}
then i tried to bind the my StartViewModel
to that ContentFrame
doing
public class MainViewModel : Screen
{
public MainViewModel()
{
this.ContentFrame = new StartViewModel(((App) Application.Current).GetDefaultInstance<INavigationService2>());
}
public DefaultViewModel ContentFrame { get; set; }
}
when I run this, the StartView
is shown inside the MainView
Grid, but navigation does not longer navigate to the right view/viewmodel (it actually loads the MainViewModel again somehow).
Since this is not really nice and straight forward, I wanted your ideas on how to achieve the original problem: sharing the mediaelement between pages/views.