I have a WPF project using the MVVM model.
In my View, I have set up an invisible WebBrowser
named myWebBrowser which is used to perform actions on the net (it seems that when I create the WebBrowser
dynamically it does not work as intended).
I also have, in my View, a button which, when clicked, would normally launch a void action that is set up in the ViewModel. That's fine. The issue I am having is that I want that void to do some events such as:
myWebBrowser.Navigate(url)
myWebBrowser.LoadCompleted += WebBrowserLoaded;
and basically launch the process using the invisible WebBrowser
that is in the View.
How can I achieve this as the ViewModel refuses for me to use a control name to reference it?
try to use EventToCommand, if your webbrowser is hidden element in xaml.
You can create an
Attached Property
to do this for you:You could then use it like this:
To update the content, simply change the value of the
YourUrlProperty
property.Sheridan's answer is perfect but you might need to include the
xmlns attribute
If you are using
namespaces
:xmlns:Attached="clr-namespace:foo.my.namespace"