Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit f895926

Browse files
committed
Use Rx to wait for IsLoaded==true
1 parent b7fcf23 commit f895926

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

src/GitHub.TeamFoundation.14/Services/TeamExplorerServices.cs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public async Task ShowRepositorySettingsRemotesAsync()
7171
var te = serviceProvider.TryGetService<ITeamExplorer>();
7272
var page = await NavigateToPageAsync(te, repositorySettingsPageId);
7373
var remotes = page?.GetSection(remotesSectionId);
74-
BringIntoView(remotes);
74+
await BringIntoViewAsync(remotes);
7575
}
7676

7777
public void ShowMessage(string message)
@@ -127,26 +127,24 @@ void OpenFolder(string repositoryPath)
127127
dte?.ExecuteCommand("File.OpenFolder", repositoryPath);
128128
}
129129

130-
static void BringIntoView(ITeamExplorerSection section)
130+
static async Task BringIntoViewAsync(ITeamExplorerSection section)
131131
{
132-
var control = section?.SectionContent as UserControl;
133-
if (control != null)
132+
var content = section?.SectionContent as UserControl;
133+
if (section == null)
134134
{
135-
if (control.IsLoaded)
136-
{
137-
BringIntoView();
138-
}
139-
else
140-
{
141-
control.Loaded += (s, e) => BringIntoView();
142-
}
135+
return;
143136
}
144137

145-
void BringIntoView()
146-
{
147-
var targetRectangle = new Rect(0, 0, 0, 1000);
148-
control.BringIntoView(targetRectangle);
149-
}
138+
// Wait for section content to load
139+
await Observable.FromEventPattern(content, nameof(content.Loaded))
140+
.Select(e => content.IsLoaded)
141+
.StartWith(content.IsLoaded)
142+
.Where(l => l == true)
143+
.Take(1);
144+
145+
// Specify a tall rectangle to bring section to the top
146+
var targetRectangle = new Rect(0, 0, 0, 1000);
147+
content.BringIntoView(targetRectangle);
150148
}
151149

152150
static async Task<ITeamExplorerPage> NavigateToPageAsync(ITeamExplorer teamExplorer, Guid pageId)

0 commit comments

Comments
 (0)