@@ -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