Exemple #1
0
        /// <summary>
        /// Callback when a key is pressed in the searchbox
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SearchTextKeyPressed(object sender, KeyEventArgs e)
        {
            if ((e.Key == Key.Up || e.Key == Key.Down) && CandidatesListBox.Items.Count > 0)
            {
                int direction = (e.Key == Key.Up) ? -1 : 1;

                int index    = CandidatesListBox.SelectedIndex;
                int maxIndex = CandidatesListBox.Items.Count - 1;
                int newIndex = index + direction;

                newIndex = (newIndex > maxIndex) ? 0 : (newIndex < 0) ? maxIndex : newIndex;

                CandidatesListBox.SelectedItem = CandidatesListBox.Items[newIndex];
            }
            else if (e.Key == Key.Enter)
            {
                StopTimer();
                UpdateSource(sender as TextBox);
                ExecuteSearchCommand();
            }
            else if (e.Key == Key.Escape)
            {
                GeoLocatorViewModel viewModel = this.GeoLocatorViewModel;
                if (viewModel != null)
                {
                    if (viewModel.GeoLocatorResults != null)
                    {
                        // Close the popup
                        viewModel.GeoLocatorResults = null;
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Constructs the place finder view model for the specified messenger
        /// </summary>
        public LiteMapPlaceFinderViewModel(Messenger messenger = null)
            : base(messenger)
        {
            // Instead of sub-classing the toolkit's GeoLocatorViewModel and working with On<property>Changed overrides,
            // let's create one directly and use event handlers for dealing with changes in the result
            GeoLocatorViewModel = new GeoLocatorViewModel(messenger)
            {
                DoReplaceSearchStringWithActiveResult = false,
                DoShowPopupWithSingleCandidate        = true
            };

            // Set up the event handler
            GeoLocatorViewModel.ResultActivated += GeoLocatorViewModel_ResultActivated;

            // Set up the recently visited items view model for being able to navigate back
            // to previously visited elements
            RecentItemsViewModel = new LiteMapRecentlyVisitedItemViewModel(messenger);

            // Property change handling
            GeoLocatorViewModel.PropertyChanged  += GeoLocatorViewModel_PropertyChanged;
            RecentItemsViewModel.PropertyChanged += RecentItemsViewModel_PropertyChanged;

            // Typing delay before sending request to the geoLocator Viewmodel
            TypingDelayBeforeSendingRequest = 750;

            // Set up the resources
            this.Resources = new ApplicationResources();

            // Register to the Messenger
            RegisterToMessenger();
        }