diff --git a/src/NuGet.Clients/NuGet.PackageManagement.UI/Xamls/PackageDetailsTabControl.xaml b/src/NuGet.Clients/NuGet.PackageManagement.UI/Xamls/PackageDetailsTabControl.xaml
index 7a209baf3fe..d4fc17a05ca 100644
--- a/src/NuGet.Clients/NuGet.PackageManagement.UI/Xamls/PackageDetailsTabControl.xaml
+++ b/src/NuGet.Clients/NuGet.PackageManagement.UI/Xamls/PackageDetailsTabControl.xaml
@@ -1,4 +1,5 @@
-
+ Content="{Binding ElementName=PackageDetailsTab, Path=PackageReadmeControl}"
+ />
diff --git a/src/NuGet.Clients/NuGet.PackageManagement.UI/Xamls/PackageDetailsTabControl.xaml.cs b/src/NuGet.Clients/NuGet.PackageManagement.UI/Xamls/PackageDetailsTabControl.xaml.cs
index 6364b9d4553..c77d914a951 100644
--- a/src/NuGet.Clients/NuGet.PackageManagement.UI/Xamls/PackageDetailsTabControl.xaml.cs
+++ b/src/NuGet.Clients/NuGet.PackageManagement.UI/Xamls/PackageDetailsTabControl.xaml.cs
@@ -24,8 +24,11 @@ public PackageDetailsTabControl()
{
InitializeComponent();
DataContext = new PackageDetailsTabViewModel();
+ PackageReadmeControl = new PackageReadmeControl();
}
+ public PackageReadmeControl PackageReadmeControl { get; private set; }
+
public void Dispose()
{
Dispose(disposing: true);
diff --git a/src/NuGet.Clients/NuGet.PackageManagement.UI/Xamls/PackageManagerControl.xaml.cs b/src/NuGet.Clients/NuGet.PackageManagement.UI/Xamls/PackageManagerControl.xaml.cs
index 610c47c781a..5613f36acdc 100644
--- a/src/NuGet.Clients/NuGet.PackageManagement.UI/Xamls/PackageManagerControl.xaml.cs
+++ b/src/NuGet.Clients/NuGet.PackageManagement.UI/Xamls/PackageManagerControl.xaml.cs
@@ -148,7 +148,7 @@ private async ValueTask InitializeAsync(PackageManagerModel model, INuGetUILogge
_nugetPackageFileService = await _serviceBroker.GetProxyAsync(NuGetServices.PackageFileService, CancellationToken.None);
await _packageDetail._packageDetailsTabControl.PackageDetailsTabViewModel.InitializeAsync(_detailModel, _nugetPackageFileService, _topPanel.Filter, settings.SelectedPackageMetadataTab);
-
+ await _packageDetail._packageDetailsTabControl.PackageReadmeControl.InitializeAsync();
await InitPackageSourcesAsync(settings, CancellationToken.None);
ApplySettings(settings, Settings);
_initialized = true;
diff --git a/src/NuGet.Clients/NuGet.PackageManagement.UI/Xamls/PackageReadmeControl.xaml.cs b/src/NuGet.Clients/NuGet.PackageManagement.UI/Xamls/PackageReadmeControl.xaml.cs
index 0995db010a1..aa85ff7869d 100644
--- a/src/NuGet.Clients/NuGet.PackageManagement.UI/Xamls/PackageReadmeControl.xaml.cs
+++ b/src/NuGet.Clients/NuGet.PackageManagement.UI/Xamls/PackageReadmeControl.xaml.cs
@@ -8,6 +8,7 @@
using System.Windows.Controls;
using Microsoft.VisualStudio.Markdown.Platform;
using Microsoft.VisualStudio.Shell;
+using Microsoft.VisualStudio.Threading;
using NuGet.PackageManagement.UI.ViewModels;
using NuGet.VisualStudio;
using NuGet.VisualStudio.Telemetry;
@@ -30,6 +31,22 @@ public PackageReadmeControl()
public ReadmePreviewViewModel ReadmeViewModel { get => (ReadmePreviewViewModel)DataContext; }
+ public async Task InitializeAsync()
+ {
+ if (_markdownPreview is null)
+ {
+ await TaskScheduler.Default;
+ var componentModel = await AsyncServiceProvider.GlobalProvider.GetComponentModelAsync();
+ var markdownPreviewSingleton = componentModel.GetService();
+ await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
+ _markdownPreview = markdownPreviewSingleton.GetInstance();
+ }
+ if (descriptionMarkdownPreview.Content is null)
+ {
+ descriptionMarkdownPreview.Content = _markdownPreview.VisualElement;
+ }
+ }
+
private void ReadmeViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(ReadmePreviewViewModel.ReadmeMarkdown))
@@ -79,7 +96,6 @@ private void PackageReadmeControl_Unloaded(object sender, RoutedEventArgs e)
{
await _markdownPreview.UpdateContentAsync("", ScrollHint.None);
});
- ReadmeViewModel.PropertyChanged -= ReadmeViewModel_PropertyChanged;
}
}
@@ -87,10 +103,6 @@ private void PackageReadmeControl_Loaded(object sender, RoutedEventArgs e)
{
NuGetUIThreadHelper.JoinableTaskFactory.Run(async () =>
{
- var componentModel = await AsyncServiceProvider.GlobalProvider.GetComponentModelAsync();
- var markdownPreviewSingleton = componentModel.GetService();
- _markdownPreview = markdownPreviewSingleton.GetInstance();
- descriptionMarkdownPreview.Content = _markdownPreview.VisualElement;
await UpdateMarkdownAsync();
});
}