In order to be bindable, components must implement IBindableComponent.
I made a set of components (MenuItem, etc) that implement IBindableComponent (and IHaveName for simplicity sake).
The implementation of IBindableComponent is awkward since one must create BindingContext and DataBindings properties both on Wisej and on WinForms namespaces. Yes, that’s right. Both properties must be created twice.
Just after executing binding (changing the form property), an exception is raised: “Object reference not set to an instance of an object”. I can’t debug Wisej.Core code and need some help to fix this issue.
The nicest thing would be for ITG to implement IBindableComponent and IHaveName interfaces on your own components (something Microsoft should have done in the first place). This change request shouldn’t be that hard to implement and there is no risk of breaking existing code.
WinForms and Wisej samples attached.
Hi Tiago,
WJ-8366 is fixed in Wisej 1.3.82.
Best regards
Frank
Hi Tiago,
Thanks. The null reference is caused by a fix we added to the dev build to overcome a shortcoming of the winforms binding where controls that are not made visible at least once don’t bind. The fix of course didn’t take in consideration binding of non Control components. Will be fixed in the release.
For the IBindableComponent the problem is that it extends the WinForms.IBindableComponent – the data binding in Wisej is extended from the winforms data binding. The properties are shadowed but we didn’t consider custom implementations. The easiest way to simplify this is to let the interface only require the winforms-declared properties. This way you’d have to declare the two properties only once in custom IBindableComponent implementations.
The Wisej components and controls already provide the Wisej equivalent properties.
Let me know you thoughts on this.
Best,
Luca
Hi Luca,
I took your suggestion a step further and forgot all about Wisej.Web.IBindableComponent and used instead System.Windows.Forms.IBindableComponent.
The end result work as well as the other one, meaning it raises the same exception after changing one form property.
using System.ComponentModel;
#if WISEJ
using System.Windows.Forms;
#else
using System.Windows.Forms;
#endifnamespace MvvmFx.WisejWeb
{
/// <summary>
/// Data binding enabled StatusBarPanel.
/// </summary>
public class StatusBarPanel : Wisej.Web.StatusBarPanel, IBindableComponent, IHaveName
{
#region IBindableComponent Membersprivate BindingContext _bindingContext;
private ControlBindingsCollection _dataBindings;/// <summary>Gets or sets the collection of currency managers for the <see cref=”System.Windows.Forms.IBindableComponent” />. </summary>
/// <returns>The collection of <see cref=”System.Windows.Forms.BindingManagerBase” /> objects for this <see cref=”System.Windows.Forms.IBindableComponent” />.</returns>
/// <filterpriority>1</filterpriority>
[Browsable(false)]
public BindingContext BindingContext
{
get
{
if (_bindingContext == null)
{
_bindingContext = new BindingContext();
}
return _bindingContext;
}
set { _bindingContext = value; }
}/// <summary>Gets the collection of data-binding objects for this <see cref=”System.Windows.Forms.IBindableComponent” />.</summary>
/// <returns>The <see cref=”System.Windows.Forms.ControlBindingsCollection” /> for this <see cref=”System.Windows.Forms.IBindableComponent” />. </returns>
/// <filterpriority>1</filterpriority>
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public ControlBindingsCollection DataBindings
{
get
{
if (_dataBindings == null)
{
_dataBindings = new ControlBindingsCollection(this);
}
return _dataBindings;
}
}/*/// <summary>Gets or sets the collection of currency managers for the <see cref=”System.Windows.Forms.IBindableComponent” />. </summary>
/// <returns>The collection of <see cref=”System.Windows.Forms.BindingManagerBase” /> objects for this <see cref=”System.Windows.Forms.IBindableComponent” />.</returns>
System.Windows.Forms.BindingContext System.Windows.Forms.IBindableComponent.BindingContext
{
get { return BindingContext; }set { BindingContext = (BindingContext) value; }
}/// <summary>Gets the collection of data-binding objects for this <see cref=”System.Windows.Forms.IBindableComponent” />.</summary>
/// <returns>The <see cref=”System.Windows.Forms.ControlBindingsCollection” /> for this <see cref=”System.Windows.Forms.IBindableComponent” />.</returns>
System.Windows.Forms.ControlBindingsCollection System.Windows.Forms.IBindableComponent.DataBindings
{
get { return DataBindings; }
}*/#endregion
}
}
So your suggestion is all right, provided it makes the declaration easier.
Hi Tiago,
for the null reference exception I have logged WJ-8366 and as Luca already mentioned it will be fixed in the next release.
Thanks,
Frank
Please login first to submit.