Search code examples
wpfxamldotnetbrowser

Create WPF BrowserView defined in XAML with custom BrowserContext


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?


Solution

  • 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).