private void LoadPackage(IPackage package, string packagePath, PackageType packageType) { DisposeViewModel(); if (package != null) { if (!HasLoadedContent <PackageViewer>()) { var packageViewer = new PackageViewer(UIServices, PackageChooser); var binding = new Binding { Converter = new NullToVisibilityConverter(), FallbackValue = Visibility.Collapsed }; packageViewer.SetBinding(VisibilityProperty, binding); MainContentContainer.Children.Add(packageViewer); // HACK HACK: set the Export of IPackageMetadataEditor here EditorService = packageViewer.PackageMetadataEditor; } PackageViewModel packageViewModel = PackageViewModelFactory.CreateViewModel(package, packagePath); packageViewModel.PropertyChanged += OnPackageViewModelPropertyChanged; DataContext = packageViewModel; if (!String.IsNullOrEmpty(packagePath)) { _mruManager.NotifyFileAdded(package, packagePath, packageType); } } }
private async void LoadPackage(IPackage package, string packagePath, PackageType packageType) { DisposeViewModel(); if (package != null) { if (!HasLoadedContent <PackageViewer>()) { var packageViewer = new PackageViewer(SettingsManager, UIServices, PackageChooser); var binding = new Binding { Converter = new NullToVisibilityConverter(), FallbackValue = Visibility.Collapsed }; packageViewer.SetBinding(VisibilityProperty, binding); MainContentContainer.Children.Add(packageViewer); // HACK HACK: set the Export of IPackageMetadataEditor here EditorService = packageViewer.PackageMetadataEditor; } try { var packageViewModel = await PackageViewModelFactory.CreateViewModel(package, packagePath); packageViewModel.PropertyChanged += OnPackageViewModelPropertyChanged; DataContext = packageViewModel; if (!string.IsNullOrEmpty(packagePath)) { _mruManager.NotifyFileAdded(package, packagePath, packageType); } } catch (Exception e) { if (!(e is ArgumentException)) { DiagnosticsClient.Notify(e); } UIServices.Show($"Error loading package\n{e.Message}", MessageLevel.Error); } } }