OneWay binding to WinForms?

I have a control with a property public MyClass MyProperty{...}whose value is displayed on the screen in a graph. I want this property to be bound to any other MyClassin the program using the class Binding( MyPropertyit would be a parameter propertyNameto this constructor Binding , and the other MyClasswould be a parameter dataMember).

MyClassimplements INotifyPropertyChanged, so everything is in order on this side. But it happens that if I do not implement the accessor getin MyPropertyand try to associate something with it, I get the message "I cannot bind the MyProperty property to the target control. Parameter name: Error PropertyName".

Does this mean that I had to implement the accessory get, even if I know that I will never need to read it, and I want to bind OneWay (source to the target), and even if I just return it nullto the accessory get?

I guess the class Bindinguses this to compare a new value with an old one or do some other internal things. I'm not sure if nullit would be a good idea to just return it , or it would be better to always keep a copy of any last object with an accessor setand return it to the getharness. Maybe I don’t even need to write an accessory get, and I'm doing something else wrong. It just happens that I get an error only when I comment on an accessory getand stop receiving it when I return it.

Edit: If there is any confusion: when I say the MyPropertyvalue is displayed on the screen in a graph, I do not mean that it has a value that reads another code and displays on the screen. No one reads values ​​from MyProperty. MyProperty setAccessor is the one that draws the material on the screen and that is the end of the loop.

+5
source share
1 answer

I am not 100% sure, I understand what you mean, but I think that the exception you encounter stems from the Bindingclass function CheckBinding(reflection):

if (descriptor.IsReadOnly && (this.controlUpdateMode != ControlUpdateMode.Never))
{
    throw new ArgumentException(SR.GetString("ListBindingBindPropertyReadOnly", new object[] { this.propertyName }), "PropertyName");
}

Consequently, changing the binding ControlUpdateModeto ControlUpdateMode.Nevermay be what you are looking for

+6
source

All Articles