/// <summary> /// If the user did not manually select a station via the dialog or the dropdown of the /// <see cref="ComboBox"/>, this method will check the content of the <see cref="ComboBox"/> /// and load a station into the <see cref="ComboBox"/>, that is valid. The station is /// only going to be loaded into the <see cref="ComboBox"/>, if there's only one result. /// </summary> /// <param name="combobox">The combobox to apply it for.</param> /// <param name="continuation">The continuation to execute.</param> /// <returns>The task to await.</returns> private async Task CheckIfComboboxStationEmpty(ComboBox combobox, Action continuation) { if (combobox.SelectedItem == null && combobox.Text != string.Empty) { var searchText = combobox.Text; var stationList = await Task.Run(() => this.actionHandler.HandleFunc(() => this.queryService.GetStations(searchText))); if (stationList != null && stationList.StationList.Any()) { if (stationList.StationList.Any(x => x.Name == searchText) || stationList.StationList.Count == 1) { // If there's only one result, create the view model and load it into the combo box var viewModel = new ComboboxItemViewModel <TransportStation>( stationList.StationList.FirstOrDefault(x => x.Name == searchText) ?? stationList.StationList.First(), x => x.Name); combobox.DataSource = new List <object> { viewModel }; combobox.SelectedItem = viewModel; } } } // Invoke the continuation on the UI thread this.Invoke(continuation); }
/// <summary> /// Gets the closest station view model to the current location. /// </summary> /// <returns>Returns the view model for the curent location <see cref="TransportStation"/>.</returns> private async Task <ComboboxItemViewModel <TransportStation> > GetCurrentLocationComboboxViewModel() { var closeLocation = await Task.Run(() => this.actionHandler.HandleFunc( () => this.locatableStationService.GetClosestStation(), exception => { })); if (closeLocation != null) { var viewModel = new ComboboxItemViewModel <TransportStation>(closeLocation, x => $"Aktueller Standort: {x.Name}"); return(viewModel); } return(null); }