private async Task GetWavHeader() { var dlg = new OpenFileDialog(); dlg.Filters.Add(new FileDialogFilter() { Name = "WAV Files", Extensions = { "wav" } }); dlg.Filters.Add(new FileDialogFilter() { Name = "All Files", Extensions = { "*" } }); dlg.AllowMultiple = true; var result = await dlg.ShowAsync(); if (result != null) { string[] fileNames = result; var sb = new StringBuilder(); int totalFiles = 0; foreach (string fileName in fileNames) { try { using (var fs = File.OpenRead(fileName)) { var h = WavFileInfo.ReadFileHeader(fs); if (totalFiles > 0) { sb.Append("\n\n"); } sb.Append( string.Format( "FileName:\t\t{0}\nFileSize:\t\t{1}\n{2}", Path.GetFileName(fileName), fs.Length.ToString(), h.ToString())); totalFiles++; } } catch (Exception ex) { string text = string.Format("Error: {0}\n", ex.Message); sb.Append(text); textOutput.Text = sb.ToString(); } } textOutput.Text = sb.ToString(); } }
/// <inheritdoc/> public async Task<string> GetImageKeyAsync() { try { var dlg = new OpenFileDialog(); dlg.Filters.Add(new FileDialogFilter() { Name = "All", Extensions = { "*" } }); var result = await dlg.ShowAsync(_serviceProvider.GetService<MainWindow>()); if (result != null) { var fileIO = _serviceProvider.GetService<IFileSystem>(); var path = result.FirstOrDefault(); using (var stream = fileIO.Open(path)) { var bytes = fileIO.ReadBinary(stream); var key = _serviceProvider.GetService<ProjectEditor>().Project?.AddImageFromFile(path, bytes); return key; } } } catch (Exception ex) { _serviceProvider.GetService<ILog>().LogError($"{ex.Message}{Environment.NewLine}{ex.StackTrace}"); } return null; }
private async Task promptForFileThatExists() { var dialog = new Avalonia.Controls.OpenFileDialog(); //dialog.Filters.Add(new FileDialogFilter(){Name = "All", Extensions = {"*"}}); var initialDirectory = getInitialDirectory(); if (initialDirectory.IsSet) { dialog.Directory = initialDirectory.Value; } if (!string.IsNullOrWhiteSpace(FilePath)) { dialog.InitialFileName = System.IO.Path.GetFileName(FilePath); } // how to get the window from a control: https://stackoverflow.com/questions/56566570/openfiledialog-in-avalonia-error-with-showasync var win = (Window)this.GetVisualRoot(); string[] result = await dialog.ShowAsync(win); if (result != null && result.Any()) { FilePath = result.First(); } }
private async Task SplitWavFiles() { var dlg = new OpenFileDialog(); dlg.Filters.Add(new FileDialogFilter() { Name = "WAV Files", Extensions = { "wav" } }); dlg.Filters.Add(new FileDialogFilter() { Name = "All Files", Extensions = { "*" } }); dlg.AllowMultiple = true; var result = await dlg.ShowAsync(); if (result != null) { await SplitWavFiles(result); } }
public MainWindowViewModel() { Items = new List<TestItem>(); for (int i = 0; i < 10; ++i) { Items.Add(new TestItem($"Item {i}", $"Item {i} Value")); } Nodes = new List<TestNode> { new TestNode { Header = "Root", SubHeader = "Root Item", IsExpanded = true, Children = new[] { new TestNode { Header = "Child 1", SubHeader = "Child 1 Value", }, new TestNode { Header = "Child 2", SubHeader = "Child 2 Value", IsExpanded = false, Children = new[] { new TestNode { Header = "Grandchild", SubHeader = "Grandchild Value", }, new TestNode { Header = "Grandmaster Flash", SubHeader = "White Lines", }, } }, } } }; CollapseNodesCommand = ReactiveCommand.Create(); CollapseNodesCommand.Subscribe(_ => ExpandNodes(false)); ExpandNodesCommand = ReactiveCommand.Create(); ExpandNodesCommand.Subscribe(_ => ExpandNodes(true)); OpenFileCommand = ReactiveCommand.Create(); OpenFileCommand.Subscribe(_ => { var ofd = new OpenFileDialog(); ofd.ShowAsync(); }); OpenFolderCommand = ReactiveCommand.Create(); OpenFolderCommand.Subscribe(_ => { var ofd = new OpenFolderDialog(); ofd.ShowAsync(); }); shell = ShellViewModel.Instance; }
public async void OpenSolution() { var dlg = new OpenFileDialog(); dlg.Title = "Open Solution"; var allExtensions = new List<string>(); foreach (var solutionType in shell.SolutionTypes) { allExtensions.AddRange(solutionType.Extensions); } dlg.Filters.Add(new FileDialogFilter { Name = "All Supported Solution Types", Extensions = allExtensions }); foreach (var solutionType in shell.SolutionTypes) { dlg.Filters.Add(new FileDialogFilter { Name = solutionType.Description, Extensions = solutionType.Extensions }); } dlg.InitialFileName = string.Empty; dlg.InitialDirectory = Platform.ProjectDirectory; var result = await dlg.ShowAsync(); if (result != null) { await shell.OpenSolutionAsync(result[0]); } }