Search code examples
c#wpfcefsharp

WPF Cefsharp instance/object reference in class not working


I am spending too much time trying to solve this issue: i am trying to create a Core, because the project is already confusing me and it is not that big. The Core is a Class outside the main Thread. On the main Thread i named the Browser, browser :

<cefSharp:ChromiumWebBrowser x:Name="browser" x:FieldModifier="public" />

In the class i call it like this:

 public class Core : MainWindow
{

    public void winstenVerlies()
    {
        var currentdirectory = "https://www.google.nl";
        this.browser.Address = currentdirectory;

    }
}

I have tried numerous ways, this is the way i like it but they all give me the same message:

"object reference is not set on an instance of an object."

Any help is appreciated.


Solution

  • Problem solved. i researched it for weeks now, from what i can see is the problem is the root, when i use this or the object/function name when calling it, it does not get passed the root of the class, instead of the root of the project. here is how you bypass it. pass the object trough the class.

     public void  winstenVerlies(ChromiumWebBrowser b)
        {
    
           var currentdirectory = "https://www.google.nl";
           b.Address = currentdirectory;
    
        }
    

    then call it like so.

    Core Menu = new Core();
    Menu.winstenVerlies(browser);
    

    Now i try'd this befor, it gave me error messages the last time, i did not trace the source of the problems. All i know is it working now, and i am happy. Have a nice day.