Пример #1
0
        private static async void OpenFile()
        {
            if (ApplicationView.Value != ApplicationViewState.Snapped || ApplicationView.TryUnsnap())
            {
                Debug.Log("OpenFile...");

                Selection.Clear();
                LastOpenFiles.Clear();
                IsBusy = true;

                try
                {
                    FileOpenPicker openPicker = new FileOpenPicker();
                    openPicker.ViewMode = CurrentViewMode;
                    openPicker.SuggestedStartLocation = CurrentLocation;

                    foreach (string ext in Extensions.SelectMany(extension => extension.Extensions))
                    {
                        openPicker.FileTypeFilter.Add(ext.StartsWith("*") ? ext : "." + ext);
                    }

                    StorageFile file = await openPicker.PickSingleFileAsync();

                    if (file != null)
                    {
                        Selection.Add(file.Path);
                        LastOpenFiles.Add(file);
                    }
                }
                catch (Exception ex)
                {
                    Debug.LogError(ex.ToString());
                }

                IsBusy = false;

                Debug.Log("OpenFile end: " + Selection.Count);
            }
            else
            {
                Debug.LogError("OpenFile: could not unsnap! " + Selection.Count);
            }
        }