Пример #1
0
        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            base.OnNavigatedFrom(e);

            Microsoft.Devices.CameraButtons.ShutterKeyPressed -= CameraButtons_ShutterKeyPressed;

            DataContext = null;

            _photoResult = null;

            if (_viewModel != null)
            {
                _viewModel.Photos.CollectionChanged -= Photos_CollectionChanged;
                _viewModel = null;
            }
        }
        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            base.OnNavigatedFrom(e);

            Microsoft.Devices.CameraButtons.ShutterKeyPressed -= CameraButtons_ShutterKeyPressed;

            DataContext = null;

            _photoResult = null;

            if (_viewModel != null)
            {
                _viewModel.Photos.CollectionChanged -= Photos_CollectionChanged;
                _viewModel = null;
            }
        }
Пример #3
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (e.NavigationMode == NavigationMode.New)
            {
                if (NavigationContext.QueryString.ContainsKey("picker"))
                {
                    _picker = true;

                    GuideTextBlock.Text = AppResources.PhotosPage_PickerGuideTextBlock_Text;
                }
                else
                {
                    GuideTextBlock.Text = AppResources.PhotosPage_StandaloneGuideTextBlock_Text;

                    // Gallery button

                    var galleryButton = new ApplicationBarIconButton()
                    {
                        IconUri = new Uri("/Assets/Icons/folder.png", UriKind.Relative),
                        Text    = AppResources.ViewfinderPage_GalleryButton_Text
                    };

                    galleryButton.Click += GalleryButton_Click;

                    ApplicationBar.Buttons.Add(galleryButton);

                    // Camera button

                    var cameraButton = new ApplicationBarIconButton()
                    {
                        IconUri = new Uri("/Assets/Icons/camera.png", UriKind.Relative),
                        Text    = AppResources.PhotosPage_CameraButton_Text
                    };

                    cameraButton.Click += CameraButton_Click;

                    ApplicationBar.Buttons.Add(cameraButton);

                    // About menu item

                    var aboutMenuItem = new ApplicationBarMenuItem()
                    {
                        Text = AppResources.PhotosPage_AboutMenuItem_Text
                    };

                    aboutMenuItem.Click += AboutMenuItem_Click;

                    ApplicationBar.MenuItems.Add(aboutMenuItem);

                    ApplicationBar.IsVisible = true;
                }
            }

            if (_photoResult != null)
            {
                PhotoModel.Singleton.FromCameraRollPath(_photoResult.OriginalFileName);

                if (_picker)
                {
                    NavigationService.GoBack();
                }
                else
                {
                    NavigationService.Navigate(new Uri("/Pages/MagnifierPage.xaml", UriKind.Relative));
                }
            }
            else
            {
                Microsoft.Devices.CameraButtons.ShutterKeyPressed += CameraButtons_ShutterKeyPressed;

                _viewModel = new PhotosPageViewModel();
                _viewModel.Photos.CollectionChanged += Photos_CollectionChanged;

                DataContext = _viewModel;
            }
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (e.NavigationMode == NavigationMode.New)
            {
                if (NavigationContext.QueryString.ContainsKey("picker"))
                {
                    _picker = true;

                    GuideTextBlock.Text = AppResources.PhotosPage_PickerGuideTextBlock_Text;
                }
                else
                {
                    GuideTextBlock.Text = AppResources.PhotosPage_StandaloneGuideTextBlock_Text;

                    // Gallery button

                    var galleryButton = new ApplicationBarIconButton()
                    {
                        IconUri = new Uri("/Assets/Icons/folder.png", UriKind.Relative),
                        Text = AppResources.ViewfinderPage_GalleryButton_Text
                    };

                    galleryButton.Click += GalleryButton_Click;

                    ApplicationBar.Buttons.Add(galleryButton);

                    // Camera button

                    var cameraButton = new ApplicationBarIconButton()
                    {
                        IconUri = new Uri("/Assets/Icons/camera.png", UriKind.Relative),
                        Text = AppResources.PhotosPage_CameraButton_Text
                    };

                    cameraButton.Click += CameraButton_Click;

                    ApplicationBar.Buttons.Add(cameraButton);

                    // Delete all menu item

                    _deleteAllMenuItem = new ApplicationBarMenuItem()
                    {
                        Text = AppResources.PhotosPage_DeleteAllMenuItem_Text
                    };

                    _deleteAllMenuItem.Click += DeleteAllMenuItem_Click;

                    ApplicationBar.MenuItems.Add(_deleteAllMenuItem);

                    // About menu item

                    var aboutMenuItem = new ApplicationBarMenuItem()
                    {
                        Text = AppResources.PhotosPage_AboutMenuItem_Text
                    };

                    aboutMenuItem.Click += AboutMenuItem_Click;

                    ApplicationBar.MenuItems.Add(aboutMenuItem);

                    ApplicationBar.IsVisible = true;
                }
            }

            if (_photoResult != null)
            {
                PhotoModel.Singleton.FromLibraryImage(_photoResult.OriginalFileName, _photoResult.ChosenPhoto);

                if (_picker)
                {
                    NavigationService.GoBack();
                }
                else
                {
                    NavigationService.Navigate(new Uri("/Pages/MagnifierPage.xaml", UriKind.Relative));
                }
            }
            else
            {
                Microsoft.Devices.CameraButtons.ShutterKeyPressed += CameraButtons_ShutterKeyPressed;

                _viewModel = new PhotosPageViewModel();
                _viewModel.Photos.CollectionChanged += Photos_CollectionChanged;

                AdaptToPhotosCollection();

                DataContext = _viewModel;
            }
        }