The application" /> The application" /> The application"/>

Create WPF BrowserView defined in XAML with custom BrowserContext

384 Views Asked by At

I've got a DotNetBrowser instance defined in a XAML file

<Grid>
  <wpf:WPFBrowserView x:Name="BrowserView"></wpf:WPFBrowserView>
</Grid>

The application is used by multiple people, which is causing issues due to the issue discussed here:

Chromium profile directory is already used/locked by another browser

Is it possible to use XAML to define the browser control and still assign a custom context to the browser instance?

2

There are 2 best solutions below

0
mm8 On BEST ANSWER

Is it possible to use XAML to define the browser control and still assign a custom context to the browser instance?

No, I am afraid it's not.

The Browser property of the WPFBrowserView class doesn't have a public setter so you must create the custom Browser and the BrowserContext programmatically:

BrowserContextParams params1 = new BrowserContextParams("C:\\my-data1");
BrowserContext context1 = new BrowserContext(params1);
Browser browser1 = BrowserFactory.Create(context1);

XAML doesn't support anything like calling BrowserFactory.Create(context1).

0
Anna Dolbina On

Unfortunately, the custom BrowserContext can be configured only if the Browser and WPFBrowserView were created from the source code.

The possible approach is to wrap WPFBrowserView and its non-default initialization into a custom control that manages instantiating and disposal of the WPFBrowserView, make this control expose all the necessary properties and then insert it into your XAML.