I believe that you get this error because you bind TextBox.TextProperty to nm, but TextBox.TextProperty is null. With two-way binding, you first need to send the value from nm to TextBox.TextProperty, setting it to "x" so that its value is no longer when it tries to link the opposite. Removing the converter probably also removes the check, which detects that TextBox.TextProperty is null and throws an exception.
So, if you have to add a line:
oj.Fe.Text = "something";
Or perhaps even:
oj.Fe.Text = string.Empty;
front
oj.Fe.SetBinding(TextBox.TextProperty, bnd);
then you should be fine.
EDIT: Actually, it was not an empty value, but a null sourceType that threw an exception.
I looked deeper with the decompiler, and it looks like you get the exception because sourceType is NULL. The IsValidValueForUpdate function, which throws a null reference, is only triggered when there is a converter, which explains why you do not get it when you remove the converter. The code was run during the backward conversion process, which explains why this happens with "OneWayToSource" as the binding mode. Regardless of the fact that this may be a minor error in the structure, setting up a datacontext before binding to provide sourceType seems like a good way.
source share