Skip to content

Commit e48e00d

Browse files
authored
Update MultiProfile.md
1 parent a2fa44b commit e48e00d

1 file changed

Lines changed: 24 additions & 5 deletions

File tree

specs/MultiProfile.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ data storage etc., to help you build a more wonderful experience for your applic
2121

2222
# Examples
2323

24-
## Provide options to create WebView2 with a specific profile
24+
## Win32 C++
2525

26-
### Win32 C++
26+
### Provide options to create WebView2 with a specific profile
2727

2828
```cpp
2929
HRESULT AppWindow::CreateControllerWithOptions()
@@ -79,9 +79,7 @@ HRESULT AppWindow::CreateControllerWithOptions()
7979
}
8080
```
8181

82-
## Access the profile property of WebView2
83-
84-
### Win32 C++
82+
### Access the profile property of WebView2
8583

8684
```cpp
8785
HRESULT AppWindow::OnCreateCoreWebView2ControllerCompleted(HRESULT result, ICoreWebView2Controller* controller)
@@ -119,6 +117,27 @@ HRESULT AppWindow::OnCreateCoreWebView2ControllerCompleted(HRESULT result, ICore
119117
// ...
120118
}
121119
```
120+
## .NET and WinRT
121+
122+
### Create WebView2 with a specific profile, then access the profile property of WebView2
123+
124+
```csharp
125+
CoreWebView2Environment _webViewEnvironment;
126+
public CreateWebView2ControllerWithOptions(IntPtr parentHWND, string profileName, bool isInPrivate)
127+
{
128+
CoreWebView2ControllerOptions options = _webViewEnvironment.CreateCoreWebView2ControllerOptions(profileName, isInPrivate);
129+
CoreWebView2Controller webView2Controller = await _webViewEnvironment.CreateCoreWebView2ControllerWithOptionsAsync(parentHWND, options);
130+
string profilePath = webView2Controller.CoreWebView2.Profile.ProfilePath;
131+
string profileDirName = profilePath.Substring(profilePath.LastIndexOf('\\') + 1);
132+
bool inPrivate = webView2Controller.CoreWebView2.Profile.IsInPrivateModeEnabled;
133+
134+
// update window title with profileDirName
135+
UpdateAppTitle();
136+
137+
// update window icon
138+
SetAppIcon(inPrivate);
139+
}
140+
```
122141

123142
# API Details
124143

0 commit comments

Comments
 (0)