/// <summary> /// Subscribes to the messager for a certain message. /// </summary> /// <param name="messageName">The name of the message to subscribe for.</param> /// <param name="callback">The callback that should be fired when the message is received.</param> /// <returns></returns> protected Messaging.MessagingTicket SubscribeToMessage(string messageName, Action <object, Action <object> > callback) { //Checks if the message name is valid. if (string.IsNullOrWhiteSpace(messageName)) { throw new ArgumentNullException("messageName"); } //Check if this view model already has a subscription for this message. if (ticketList.Any(x => x.Name == messageName)) { throw new Exception("You are already subscribed to this message."); } //Lets the Messenger know we exist if we haven't already. if (!Messenger.IsTarget((IMessagingTarget)this)) { Messenger.AddTarget(this); } //Create the ticke (representing our subscription) with the message name/id and the callback. var ticket = new Messaging.MessagingTicket(messageName, callback); //Add the ticket/subscription to our own list. ticketList.Add(ticket); //Return the ticket/subscription. return(ticket); }
public AppShellView() { this.InitializeComponent(); coreApplicationView = CoreApplication.GetCurrentView(); //if (coreApplicationView != null) // coreApplicationView.TitleBar.ExtendViewIntoTitleBar = true; applicationView = ApplicationView.GetForCurrentView(); applicationView.TitleBar.BackgroundColor = Colors.Transparent; applicationView.TitleBar.ButtonBackgroundColor = Colors.Transparent; applicationView.TitleBar.InactiveBackgroundColor = Colors.Transparent; uiSettings = new Windows.UI.ViewManagement.UISettings(); NavView.SetBinding(Microsoft.UI.Xaml.Controls.NavigationView.MenuItemsSourceProperty, NepApp.CreateBinding(NepApp.UI, nameof(NepApp.UI.NavigationItems))); inlineNavigationService = WindowManager.GetNavigationManagerForCurrentView().RegisterFrameAsNavigationService(InlineFrame, FrameLevel.Two); windowService = WindowManager.GetWindowServiceForCurrentView(); UpdateSelectedNavigationItems(); NepApp.UI.SetNavigationService(inlineNavigationService); inlineNavigationService.Navigated += InlineNavigationService_Navigated; NepApp.UI.SetOverlayParentAndSnackBarContainer(OverlayPanel, snackBarGrid); App.RegisterUIDialogs(); nowPlayingOverlayCoordinator = new AppShellViewModelNowPlayingOverlayCoordinator(this); NavView.SetBinding(Microsoft.UI.Xaml.Controls.NavigationView.HeaderProperty, NepApp.CreateBinding(NepApp.UI, nameof(NepApp.UI.ViewTitle))); NowPlayingButton.SetBinding(Button.DataContextProperty, NepApp.CreateBinding(NepApp.SongManager, nameof(NepApp.SongManager.CurrentSong))); NepApp.MediaPlayer.MediaEngagementChanged += MediaPlayer_MediaEngagementChanged; NepApp.MediaPlayer.IsPlayingChanged += MediaPlayer_IsPlayingChanged; NepApp.UI.Overlay.OverlayedDialogShown += Overlay_DialogShown; NepApp.UI.Overlay.OverlayedDialogHidden += Overlay_DialogHidden; Messenger.AddTarget(this); DeviceInformation.SubplatformChanged += DeviceInformation_SubplatformChanged; if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.UI.Xaml.Media.XamlCompositionBrushBase") && Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.UI.Xaml.Media.AcrylicBrush")) { //Add acrylic. Windows.UI.Xaml.Media.AcrylicBrush myBrush = new Windows.UI.Xaml.Media.AcrylicBrush(); myBrush.BackgroundSource = Windows.UI.Xaml.Media.AcrylicBackgroundSource.HostBackdrop; myBrush.TintColor = uiSettings.GetColorValue(UIColorType.AccentDark2); myBrush.FallbackColor = uiSettings.GetColorValue(UIColorType.AccentDark2); myBrush.Opacity = 0.6; myBrush.TintOpacity = 0.5; bottomAppBar.Background = myBrush; } else { bottomAppBar.Background = new SolidColorBrush(uiSettings.GetColorValue(UIColorType.Accent)); } }
public XboxShellView() { this.InitializeComponent(); uiSettings = new Windows.UI.ViewManagement.UISettings(); ///Set up navigation inlineNavigationService = WindowManager.GetNavigationManagerForCurrentView().RegisterFrameAsNavigationService(InlineFrame, FrameLevel.Two); NepApp.UI.SetNavigationService(inlineNavigationService); inlineNavigationService.Navigated += InlineNavigationService_Navigated; inlineNavigationService.PreBackRequested += InlineNavigationService_PreBackRequested; PageTitleTextBlock.SetBinding(TextBlock.TextProperty, NepApp.CreateBinding(NepApp.UI, nameof(NepApp.UI.ViewTitle))); nowPlayingOverlayCoordinator = new XboxShellViewModelNowPlayingOverlayCoordinator(this, inlineNavigationService); ///Set up dialogs NepApp.UI.SetOverlayParentAndSnackBarContainer(OverlayPanel, snackBarGrid); App.RegisterUIDialogs(); NepApp.UI.Overlay.OverlayedDialogShown += Overlay_DialogShown; NepApp.UI.Overlay.OverlayedDialogHidden += Overlay_DialogHidden; NepApp.UI.NoChromeStatusChanged += UI_NoChromeStatusChanged; ///Set up media metadata NowPlayingTrackTextBlock.SetBinding(TextBlock.DataContextProperty, NepApp.CreateBinding(NepApp.SongManager, nameof(NepApp.SongManager.CurrentSong))); NowPlayingArtistTextBlock.SetBinding(TextBlock.DataContextProperty, NepApp.CreateBinding(NepApp.SongManager, nameof(NepApp.SongManager.CurrentSong))); NepApp.MediaPlayer.IsPlayingChanged += Media_IsPlayingChanged; //handler to allow the metadata to animate onto the screen for the first time. CurrentMediaMetadataPanel.SetBinding(Control.VisibilityProperty, NepApp.CreateBinding(NepApp.MediaPlayer, nameof(NepApp.MediaPlayer.IsMediaEngaged), binding => { binding.Converter = new Crystal3.UI.Converters.BooleanToVisibilityConverter(); })); ///Set up messaging Messenger.AddTarget(this); SetInlineFrameMarginPaddingForOverflowScrolling(); if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.UI.Xaml.Media.XamlCompositionBrushBase")) { //Add acrylic. Windows.UI.Xaml.Media.AcrylicBrush myBrush = new Windows.UI.Xaml.Media.AcrylicBrush(); myBrush.BackgroundSource = Windows.UI.Xaml.Media.AcrylicBackgroundSource.HostBackdrop; myBrush.TintColor = uiSettings.GetColorValue(UIColorType.AccentDark2); myBrush.FallbackColor = uiSettings.GetColorValue(UIColorType.AccentDark2); myBrush.Opacity = 0.6; myBrush.TintOpacity = 0.5; HeaderGrid.Background = myBrush; Windows.UI.Xaml.Media.AcrylicBrush myBrush2 = new Windows.UI.Xaml.Media.AcrylicBrush(); myBrush2.BackgroundSource = Windows.UI.Xaml.Media.AcrylicBackgroundSource.Backdrop; myBrush2.TintColor = uiSettings.GetColorValue(UIColorType.AccentDark2); myBrush2.FallbackColor = uiSettings.GetColorValue(UIColorType.AccentDark2); myBrush2.Opacity = 0.6; myBrush2.TintOpacity = 0.5; TransportControlGrid.Background = myBrush; TransportControlGrid.BorderBrush = myBrush; } else { HeaderGrid.Background = new SolidColorBrush(uiSettings.GetColorValue(UIColorType.Accent)); TransportControlGrid.Background = new SolidColorBrush(uiSettings.GetColorValue(UIColorType.Accent)); TransportControlGrid.BorderBrush = new SolidColorBrush(uiSettings.GetColorValue(UIColorType.Accent)); } }