private void SpawnNewToken(TokenDTO tokenDTO) { var newToken = new Token(); newToken.myImage.Source = new BitmapImage( new Uri(tokenDTO.AircraftImageUri, UriKind.Absolute)); newToken.myImage.Stretch = Stretch.Fill; newToken.Height = tokenDTO.Height; newToken.Width = tokenDTO.Width; Canvas.SetLeft(newToken, tokenDTO.Left); Canvas.SetTop(newToken, tokenDTO.Top); airportCanvas.Children.Add(newToken); }
private void MenuItemSaveAs_Click(object sender, RoutedEventArgs e) { var dlg = new SaveFileDialog { FileName = currentFilename ?? "Airshow Plan", DefaultExt = ".airshow", Filter = "Airshow Plans (.airshow)|*.airshow" }; bool?result = dlg.ShowDialog(); if (result == false) { return; } currentFilename = dlg.FileName; Title = AppTitle; using var s = dlg.OpenFile(); var items = airportCanvas.Children.OfType <Token>().ToArray(); var dtos = new TokenDTO[items.Length]; for (int i = 0; i < items.Length; i++) { var dto = new TokenDTO() { Top = Canvas.GetTop(items[i]), Left = Canvas.GetLeft(items[i]), Rotation = (items[i].RenderTransform as RotateTransform)?.Angle ?? 0, AircraftImageUri = items[i].myImage.Source.ToString(), Width = items[i].Width, Height = items[i].Height }; dtos[i] = dto; } var airshowLayoutDto = new AirshowLayoutDTO() { TokenDTOs = dtos }; var formatter = new BinaryFormatter(); formatter.Serialize(s, airshowLayoutDto); }