public TeleportViewModel(ChapterCharacterEntryModel entry) { _entry = entry; _locations = LocationsPreset.GetLocationsOffline(); FetchStatusText = "Fetching updated list of locations from internet..."; Task.Run(async() => { List <Location> locations = null; string fetchStatusText = "<this is a bug>"; try { locations = await LocationsPreset.FetchLocations(); fetchStatusText = "Got most up-to-date list from internet."; } catch { fetchStatusText = "There was an error while retrieving the updated location list."; } Application.Current.Dispatcher.Invoke(() => { if (locations != null) { _locations = locations; OnPropertyChanged(nameof(Locations)); } FetchStatusText = fetchStatusText; OnPropertyChanged(nameof(FetchStatusText)); }); }); OkCommand = new RelayCommand(_ => { if (SelectedIndex < 0 || SelectedIndex >= _locations.Count) { return; } var location = _locations[SelectedIndex]; _entry.PosX = location.PositionX; _entry.PosY = location.PositionY; _entry.PosZ = location.PositionZ; Application.Current.Windows.OfType <Window>().FirstOrDefault(x => x.IsActive)?.Close(); }, _ => SelectedIndex >= 0); }
public TeleportWindow(ChapterCharacterEntryModel chapterCharacter) { InitializeComponent(); DataContext = new TeleportViewModel(chapterCharacter); }