Beispiel #1
0
        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);
                }
            }
        }
Beispiel #2
0
        private async void LoadPackage(IPackage package, string packagePath, string packageSource, 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);

#if !HAS_UNO
                    // HACK HACK: set the Export of IPackageMetadataEditor here
                    EditorService = packageViewer.PackageMetadataEditor;
#endif
                }

                try
                {
                    var packageViewModel = await PackageViewModelFactory.CreateViewModel(package, packagePath, packageSource);

                    packageViewModel.PropertyChanged += OnPackageViewModelPropertyChanged;

                    DataContext = packageViewModel;
                    if (!string.IsNullOrEmpty(packageSource))
                    {
                        _mruManager.NotifyFileAdded(package, packageSource, packageType);
                    }
                }
                catch (Exception e)
                {
                    if (!(e is ArgumentException))
                    {
                        DiagnosticsClient.TrackException(e);
                    }
                    Console.WriteLine(e);
                    UIServices.Show($"Error loading package\n{e.Message}", MessageLevel.Error);
                }
            }
        }