public void AttachPlayerEvents()
        {
            Player.MediaEnded  += Player_MediaEnded;
            Player.MediaOpened += Player_MediaOpened;
            Player.MediaFailed += Player_MediaFailed;

            // AttachPlayerEvents runs after LoadState, we can now load the current track, if any
            var currentTrack = CurrentTrack;

            // We come back from Terminated, thus we assume to have been in the Stopped state for the Player
            if (null != currentTrack)
            {
                string streamUrl = currentTrack.StreamUrl;
                string trackName = currentTrack.Name;

                UIDispatcher.Execute(
                    () =>
                {
                    Player.AutoPlay = false;
                    Player.Source   = new Uri(streamUrl);
                    Player.AutoPlay = true;

                    Windows.Media.MediaControl.TrackName = trackName;
                });
            }
        }
 private void SetActive(bool active)
 {
     UIDispatcher.Execute(() =>
     {
         _progress.Active = active;
     });
 }
 internal void SetRange(int from, int to)
 {
     UIDispatcher.Execute(() =>
     {
         _progress.SetRange(from, to);
     });
 }
 public void SetTitle(string title)
 {
     UIDispatcher.Execute(() =>
     {
         _progress.Title = title;
     });
 }
 private void SetIsRunningForLong(bool value)
 {
     UIDispatcher.Execute(() =>
     {
         _progress.IsRunningForLong = value;
     });
 }
Beispiel #6
0
        /// <summary>
        /// Shows the specified yes/no question.
        /// </summary>
        /// <param name="owner">The window that owns this Message Window.</param>
        /// <param name="message">The question.</param>
        /// <returns><c>true</c> for yes and <c>false</c> for no.</returns>
        public bool ShowYesNoQuestion(string message)
        {
            OnBefore();

            var ownerWindow = GetWindow();
            var result      = MessageBoxResult.None;

            if (ownerWindow != null)
            {
                UIDispatcher.Execute(() =>
                {
                    result = MessageBox.Show(ownerWindow, message, ApplicationInfo.ProductName, MessageBoxButton.YesNo,
                                             MessageBoxImage.Question, MessageBoxResult.No, GetStyle());
                });
            }
            else
            {
                UIDispatcher.Execute(() =>
                {
                    result = MessageBox.Show(message, ApplicationInfo.ProductName, MessageBoxButton.YesNo,
                                             MessageBoxImage.Question, MessageBoxResult.No, GetStyle());
                });
            }

            OnAfter();

            return(result == MessageBoxResult.Yes);
        }
Beispiel #7
0
 public void SetActiveDocumentView(string id)
 {
     UIDispatcher.Execute(() =>
     {
         if (_viewModels.ContainsKey(id))
         {
             ActiveDocumentView = (IDocumentView)_viewModels[id].View;
         }
     });
 }
Beispiel #8
0
 public void SetActiveDocumentView(IDocumentView view)
 {
     UIDispatcher.Execute(() =>
     {
         if (DocumentViews.Contains(view))
         {
             ActiveDocumentView = view;
         }
     });
 }
        /// <summary>
        /// Update the Axis Accelerometer properties to reflect the reading changed method.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private async void NativeAccelerometer_ReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
        {
            await ThreadPool.RunAsync(
                p => UIDispatcher.Execute(() =>
            {
                AccelerometerReading accelerometerReading = args.Reading;

                UpdateAccelerometerAxis(accelerometerReading);
            })
                );
        }
 private async void UpdateConnectedClients(string str, string type)
 {
     if (!lvConnectedClients.Dispatcher.HasThreadAccess)
     {
         SetListBoxItem d = UpdateConnectedClients;
         await ThreadPool.RunAsync(operation => UIDispatcher.Execute(() => AddItem(str, type)));
     }
     else
     {
         AddItem(str, type);
     }
 }
        /// <summary>
        /// Update the <see cref="IsShaken"/> property when the device is shaken.
        /// </summary>
        /// <param name="sender">Sender details.</param>
        /// <param name="e">Shake gesture event arguments.</param>
        /// <remarks>
        /// Set the <see cref="GrowthRate"/> property 1 or less, to always reset the <see cref="IsShaken"/> property to its original state.
        /// </remarks>
        private async void Instance_ShakeGesture(object sender, ShakeGestureEventArgs e)
        {
            await ThreadPool.RunAsync(
                p => UIDispatcher.Execute(() =>
            {
                IsShaken = true;

                if (GrowthRate <= 1)
                {
                    IsShaken = false;
                }
            })
                );
        }
        public void SkipAhead()
        {
            UIDispatcher.Execute(async() =>
            {
                IsPlayerInfoMessagesPaneVisible = false;

                int numOfElements = _playList.Count();
                int radioposition = CurrentTrack != null ? CurrentTrack.RadioPosition : 0;
                radioposition++;

                CurrentTrack = _playList.FirstOrDefault(t => t.RadioPosition == radioposition);

                if (numOfElements - radioposition == 2)
                {
                    await FillPlaylist();
                }
            });
        }
 public void PlayPauseToggle()
 {
     UIDispatcher.Execute(() =>
     {
         try
         {
             if (Player.CurrentState == MediaElementState.Paused)
             {
                 Player.Play();
             }
             else
             {
                 Player.Pause();
             }
         }
         catch
         {
             Debug.WriteLine("PlayPauseToggle: Exception");
         }
     });
 }
Beispiel #14
0
        public void AddDocumentView(DocumentViewModel vm, bool setActive)
        {
            if (vm == null)
            {
                throw new ArgumentNullException(nameof(vm));
            }

            UIDispatcher.Execute(() =>
            {
                WeakEventManager <DocumentViewModel, EventArgs>
                .AddHandler(vm, "Closed", TabVm_Closed);
                _viewModels.Add(vm.UniqueId, vm);
                DocumentViews.Add(vm.View as IDocumentView);
                if (setActive)
                {
                    SetActiveDocumentView(vm.View as IDocumentView);
                }

                OnCountChanged();
            });
        }
Beispiel #15
0
        public FileDialogResult ShowSaveFileDialog(IList <FileType> fileTypes, FileType defaultFileType, string defaultFileName)
        {
            if (fileTypes == null)
            {
                throw new ArgumentNullException(nameof(fileTypes));
            }
            if (!fileTypes.Any())
            {
                throw new ArgumentException("The fileTypes collection must contain at least one item.");
            }

            FileDialogResult result = null;

            UIDispatcher.Execute(() =>
            {
                var dialog = new SaveFileDialog();
                result     = ShowFileDialog(dialog, fileTypes, defaultFileType, defaultFileName);
            });

            return(result);
        }
Beispiel #16
0
        /// <summary>
        /// Shows the message.
        /// </summary>
        /// <param name="owner">The window that owns this Message Window.</param>
        /// <param name="message">The message.</param>
        public void ShowMessage(string message)
        {
            OnBefore();
            var ownerWindow = GetWindow();

            if (ownerWindow != null)
            {
                UIDispatcher.Execute(() =>
                {
                    MessageBox.Show(ownerWindow, message, ApplicationInfo.ProductName, MessageBoxButton.OK, MessageBoxImage.None, GetStyle());
                });
            }
            else
            {
                UIDispatcher.Execute(() =>
                {
                    MessageBox.Show(message, ApplicationInfo.ProductName, MessageBoxButton.OK, MessageBoxImage.None,
                                    MessageBoxResult, GetStyle());
                });
            }
            OnAfter();
        }
        private void SetPlayerSourceToCurrentTrack()
        {
            var currentTrack = CurrentTrack;

            if (null == currentTrack)
            {
                UIDispatcher.Execute(() => Player.Source = null);

                Windows.Media.MediaControl.TrackName = "";

                return;
            }

            string streamUrl = currentTrack.StreamUrl;

            UIDispatcher.Execute(() => Player.Source = new Uri(streamUrl));

            Windows.Media.MediaControl.TrackName = currentTrack.Name;

            // Cannot be set as per the documentation http://msdn.microsoft.com/en-us/library/windows/apps/windows.media.mediacontrol.albumart(v=win.10).aspx
            // Windows.Media.MediaControl.AlbumArt = new Uri(currentTrack.Album.ImageUrl);
        }
        /// <summary>
        /// Shows the message as warning.
        /// </summary>
        /// <param name="owner">The window that owns this Message Window.</param>
        /// <param name="message">The message.</param>
        public void ShowWarning(object owner, string message)
        {
            OnBefore();
            var ownerWindow = owner as Window;

            if (ownerWindow != null)
            {
                UIDispatcher.Execute(() =>
                {
                    MessageBox.Show(ownerWindow, message, ApplicationInfo.ProductName, MessageBoxButton.OK, MessageBoxImage.Warning,
                                    MessageBoxResult, GetStyle());
                });
            }
            else
            {
                UIDispatcher.Execute(() =>
                {
                    MessageBox.Show(message, ApplicationInfo.ProductName, MessageBoxButton.OK, MessageBoxImage.Warning,
                                    MessageBoxResult, GetStyle());
                });
            }
            OnAfter();
        }
        /// <summary>
        /// Shows the specified question.
        /// </summary>
        /// <param name="owner">The window that owns this Message Window.</param>
        /// <param name="message">The question.</param>
        /// <returns><c>true</c> for yes, <c>false</c> for no and <c>null</c> for cancel.</returns>
        public bool?ShowQuestion(object owner, string message)
        {
            OnBefore();

            var ownerWindow = owner as Window;
            var result      = MessageBoxResult.None;

            if (ownerWindow != null)
            {
                UIDispatcher.Execute(() =>
                {
                    result = MessageBox.Show(ownerWindow, message, ApplicationInfo.ProductName, MessageBoxButton.YesNoCancel,
                                             MessageBoxImage.Question, MessageBoxResult.Cancel, GetStyle());
                });
            }
            else
            {
                UIDispatcher.Execute(() =>
                {
                    result = MessageBox.Show(message, ApplicationInfo.ProductName, MessageBoxButton.YesNoCancel,
                                             MessageBoxImage.Question, MessageBoxResult.Cancel, GetStyle());
                });
            }

            OnAfter();

            if (result == MessageBoxResult.Yes)
            {
                return(true);
            }
            if (result == MessageBoxResult.No)
            {
                return(false);
            }

            return(null);
        }
Beispiel #20
0
 public static T GetInstance <T>()
 {
     EnsureInitialized();
     return(UIDispatcher.Execute <T>(() => _container.GetExportedValue <T>()));
 }
Beispiel #21
0
 public static IEnumerable <T> GetInstances <T>()
 {
     EnsureInitialized();
     return(UIDispatcher.Execute <IEnumerable <T> >(() => _container.GetExportedValues <T>()));
 }
 public void Play()
 {
     UIDispatcher.Execute(() => Player.Play());
 }
Beispiel #23
0
 public T GetViewModel <T>()
 {
     return(UIDispatcher.Execute <T>(() => ServiceProvider.GetService <T>()));
 }
 public void Stop()
 {
     UIDispatcher.Execute(() => Player.Stop());
 }
 public void Pause()
 {
     // MediaControl.TrackName = string.Empty;
     UIDispatcher.Execute(() => Player.Pause());
 }
Beispiel #26
0
 public static Lazy <T> GetLazyInstance <T>()
 {
     EnsureInitialized();
     return(UIDispatcher.Execute <Lazy <T> >(() => _container.GetExport <T>()));
 }