My property notifier implementation
Posted: 07 Oct 2013, 15:53
I was able to get this to work:
This automatically notifies my display when the ContainerName property is changed.
Here is my Notifier implementation:
I tried using Generics, which would have saved me from putting the Regiser() function in the ContainerData class, but it's not that big a deal.
Anyway...this seems to work well for notification. Hopefully it will work well in other situations also, like user controls and such!
Any thoughts/suggestions?
Code: Select all
public class ContainerData : Notifier
{
private string _ContainerName;
public static void Register()
{
}
public ContainerData() : base(typeof(ContainerData))
{
}
public string ContainerName
{
get { return _ContainerName; }
set
{
if (_ContainerName != value)
{
_ContainerName = value;
NotifyPropertyChanged("ContainerName");
}
}
}
}This automatically notifies my display when the ContainerName property is changed.
Here is my Notifier implementation:
Code: Select all
public class Notifier: BaseComponent
{
private readonly Type _SubType;
private HandleRef swigCPtr;
public void NotifyPropertyChanged(string propertyName)
{
Noesis.Extend.PropertyChanged(_SubType, swigCPtr.Handle, propertyName);
}
public Notifier(IntPtr cPtr, bool cMemoryOwn)
: base(cPtr, cMemoryOwn)
{
swigCPtr = new HandleRef(this, cPtr);
}
public Notifier(Type subType)
: this(Noesis.Extend.New(subType), true)
{
_SubType = subType;
Noesis.Extend.Register(_SubType, swigCPtr.Handle, this);
}
public override void Dispose()
{
lock (this)
{
if (swigCPtr.Handle != IntPtr.Zero)
{
if (swigCMemOwn)
{
swigCMemOwn = false;
if (Kernel.IsInitialized())
{
Noesis.Extend.Delete(_SubType, swigCPtr.Handle);
}
}
swigCPtr = new HandleRef(null, IntPtr.Zero);
}
GC.SuppressFinalize(this);
base.Dispose();
}
}
}I tried using Generics, which would have saved me from putting the Regiser() function in the ContainerData class, but it's not that big a deal.
Anyway...this seems to work well for notification. Hopefully it will work well in other situations also, like user controls and such!
Any thoughts/suggestions?