Exemplo n.º 1
0
        private void PhotoSelectedCommandExecute(object o)
        {
            try
            {
                Photo photo;
                var   args = o as ItemClickEventArgs;

                if (args != null)
                {
                    photo = args.ClickedItem as Photo;
                }
                else
                {
                    photo = o as Photo;
                }

                if (photo != null)
                {
                    var photoNavParam = new PhotoNavParameter()
                    {
                        Index = PhotoCollection.IndexOf(photo), Photos = PhotoCollection.ToList()
                    };
                    NavigationService.Navigate(typeof(Views.DetailPage), photoNavParam);
                }
            }
            catch (Exception ex)
            {
                AppLogs.WriteError("[PhotoSelectedCommandExecute]", ex.ToString());
            }
        }
        public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> suspensionState)
        {
            try
            {
                lock (_locker)
                {
                    var param = parameter as PhotoNavParameter;
                    if (param != null)
                    {
                        PhotoNavParameter photoNavParam = param;
                        PhotoCollection = new ObservableCollection <Photo>(photoNavParam.Photos);

                        if (!PhotoCollection.IsEmpty())
                        {
                            var strIndex = (suspensionState.ContainsKey(nameof(SelectedPhotoIndex))) ?
                                           suspensionState[nameof(SelectedPhotoIndex)]?.ToString() : null;

                            int index;
                            index = string.IsNullOrEmpty(strIndex) ? photoNavParam.Index : Convert.ToInt32(strIndex);

                            System.Diagnostics.Debug.WriteLine("PhotoCollection Count--> {0}", photoNavParam.Photos.Count);
                            System.Diagnostics.Debug.WriteLine("photoNavParam.Index--> {0}", index);

                            SelectedPhotoIndex = index;
                        }
                    }
                }

                await Task.CompletedTask;
            }
            catch (Exception ex)
            {
                AppLogs.WriteError("[OnNavigatedToAsync]", ex.ToString());
            }
        }