Implementation of IBindableComponent raises exception

Answered
0
0

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.

Attachment
  • You must to post comments
Best Answer
0
0

Hi Tiago,

WJ-8366 is fixed in Wisej 1.3.82.

Best regards
Frank

  • You must to post comments
0
0

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

  • You must to post comments
0
0

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;
#endif

namespace MvvmFx.WisejWeb
{
/// <summary>
/// Data binding enabled StatusBarPanel.
/// </summary>
public class StatusBarPanel : Wisej.Web.StatusBarPanel, IBindableComponent, IHaveName
{
#region IBindableComponent Members

private 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.

  • You must to post comments
0
0

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

 

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.