Skip to content

Commit b56976b

Browse files
Added method to get InfoBar WPF control
1 parent a5da977 commit b56976b

File tree

1 file changed

+20
-1
lines changed
  • src/toolkit/Community.VisualStudio.Toolkit.Shared/Notifications

1 file changed

+20
-1
lines changed

src/toolkit/Community.VisualStudio.Toolkit.Shared/Notifications/InfoBar.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Threading.Tasks;
3+
using System.Windows.Controls;
34
using Microsoft.VisualStudio.Shell;
45
using Microsoft.VisualStudio.Shell.Interop;
56

@@ -17,7 +18,7 @@ public class InfoBarFactory
1718
public async Task<InfoBar?> CreateAsync(InfoBarModel model)
1819
{
1920
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
20-
21+
2122
IVsShell shell = await VS.Services.GetShellAsync();
2223
shell.GetProperty((int)__VSSPROPID7.VSSPROPID_MainWindowInfoBarHost, out object value);
2324

@@ -129,6 +130,24 @@ public async Task<bool> TryShowInfoBarUIAsync()
129130
return IsVisible;
130131
}
131132

133+
/// <summary>
134+
/// Attempts to get the underlying WPF UI element of the InfoBar
135+
/// </summary>
136+
public bool TryGetWpfElement(out Control? control)
137+
{
138+
object? uiObject = null;
139+
control = null;
140+
_uiElement?.GetUIObject(out uiObject);
141+
142+
if (uiObject is IVsUIWpfElement elm)
143+
{
144+
elm.GetFrameworkElement(out object frameworkElement);
145+
control = frameworkElement as Control;
146+
}
147+
148+
return control != null;
149+
}
150+
132151
/// <summary>
133152
/// Closes the InfoBar without the user manually had to do it.
134153
/// </summary>

0 commit comments

Comments
 (0)