WPF | ChromiumWebBrowser address binding does not affect UI - wpf

I am trying to show a ChromiumWebBrowser that navigates between local HTML files.
I set a binding to the Address property in my VM, and it works only in the initial value.
when I set the address in ViewModel binded property (navigating with custom buttons) browser does not update.
what am I missing here?
(in Snoop I can see the address indeed changes, but view is same).

Your ViewModel class must implement the INotifyPropertyChanged interface and call OnPropertyChanged whenever the ViewModel property is updated.
INotifyPropertyChanged Example

Related

Custom DependencyProperty not updating external view model

I have a UserControl that has a DataGrid in it filled with members. The DataGrid.ItemsSource is bound to an ObservableCollection on the model. The DataGrid.SelectedItem is bound to the SelectedMember field on the model. The SelectedMember._set calls NotifyPropertyChanged and the event calls SetValue() for the exposed DependencyProperty.
This UserControl is on a page. That page has a viewmodel too. I'm trying to bind the UserControl.CurrentMember to the viewmodel.SelectedMember but it's not changing. I can bind the CurrentMember.MemberName to a textbox and the box fills with the member name so it looks like the UserControl is exposing the DependencyProperty correctly. But if I bind to the model it doesn't update.
I can't find any cross bindings. The bind to the TextBox works fine. The field on the page model is new so there's nothing bound to it.
What could be the problem? Does the field on the page model need to be a DependencyProperty? The compiler would give me an error if that were the case.
I'll try and get a code sample but it's so ingrained I can't just post a couple of lines of code.
Tom P.
After combing the code and trying to replicate the problem in a new project I found the problem.
In the UserControl I set the DataContext to the Model. But the UserControl.DataContext gets overwritten when I put it on the page. What i needed to do was name the MainGrid and set the DataContext of the MainGrid to the UserControlModel. MainGrid, being private to the UserControl, won't get overwritten. Now it works wonderfully.

Multibinding not firing when the bound properties change

I have a wpf wpplication with a number of user controls in it. One of these controls has a property called ButtonsEnabled. This is a bool DependencyProperty in the user control. The property is bound to the IsEnabled property of a couple of buttons on that control.
This user control is used in the MainWindow. The MainWindow has a couple of view model objects in it called EocMonitor and ComMonitor. These both descend from an abstract base class that implements INotifyPropertyChanged. The ButtonsEnabled property on the UserControl is bound to the Status property using a multibinding and a class that implements IMultiConverter that I wrote.
The problem is that even though the PropertyChanged event is being raised when the Status property changes, the IMultiConverter is not being called after it is initially called, so the value of the ButtonsEnabled property is not changing. As a result, the buttons are not enabling.
What do I need to do to make this work?
I did an end-run around this problem as I am running out of time before we reach our code-freeze for this release. What I did was I added a ButtonsEnabled DepdendencyProperty to the MainWindow class and bound it to the user control's ButtonsEnabled property. I then added a PropertyChanged event handler in the MainWindow and and registered it with the DbMonitor and ComMonitor objects when they were created. I then wrote code in the PropertyChanged event handler to set the MainWindow's ButtonsEnabled properly.
Everything works and I'll worry about making the other approach work at some later time. Maybe.

silverlight databinding not working from scriptable member

We have exposed a silverlight page as a scriptable object. It has one scriptable member.
The page's datacontext is a viewmodel object, of typ TestViewModel with one property string Description. The TestViewModel implements INotifyPropertyChanged.
The page has a textbox bound to this Description property
When Description is set to some value from within method marked with the ScriptableMember attribute, the textbox does not change
I also have a button. When I set the Description property from the click event handler of the button, the textbox changes on my page, showing the correct value.
Any reason why databinding does not work from a scriptable member and if there is a way to make it work?
You have to make sure that "HtmlPage.RegisterScriptableObject(string scriptKey, object instance)" is set on the right place. Place it in the constructor of the xaml.cs of the page where the method with the ScriptableMember attribute is used.

wpf binding 2 properties of 2 classes

I have a XAML-object (window-control) having his own-properties in the code-behind (in my case it has a property called 'FirstEditableDate' without any UI-binding).
I also have another XAML-object (user-control) with a property (also without UI) and I want to bind the other property to this property.
So, if the property of the (main)class is changing, the other property of the usercontrol is also changing.
How can I do this?
(see for examples my 'answer' below...)
You can implement the INotifyPropertyChanged interface on the Main class and have the usercontrol handle the PropertyChange event.

Can we update a source that is not DepencyProperty or not INotifyPropertyChanged compliant

I have a business object that comes from the core of the application. That object does not inherit from INotifyPropertyChanged. It contains some property that my XAML code bind to it.
I only want to update the properties not the UI dynamically (OneWayToSource style).
By example, if I change the text of a text box, the source item does not get updated.
It is a limitation of silverlight that if the object does not implement INotifyPropertyChanged or use DepencyProperties that the source of the binding cannot be updated?
The source property does not need to be a dependency property nor does the class that exposes it need to implement INotifyPropertyChanged.
If you have the binding on the TextBox set to use the TwoWay mode editing the text box should update the bound property even if it is a plain "vanila" property. Note by default the focus has to leave the TextBox in order for the binding to update.
If your business object has a set method on the property you want to update, then the value should be updated, provided the value you enter doesn't trigger an exception.
Not implementing INotifyPropertyChanged hinders just visual feedback.

Resources