-
- jc_lvngstn
- Posts: 34
- Joined:
My property notifier implementation
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?
-
-
sfernandez
Site Admin
- Posts: 3197
- Joined:
Re: My property notifier implementation
We are working on the Unity API to get rid of all the annoying boilerplate code needed to extend NoesisGUI.
One of the things we have already done is to define this same NotifyPropertyChanged function you exposed here in the BaseComponent class, so it could be accessible to any extended class.
One of the things we have already done is to define this same NotifyPropertyChanged function you exposed here in the BaseComponent class, so it could be accessible to any extended class.
-
- jc_lvngstn
- Posts: 34
- Joined:
Re: My property notifier implementation
That sounds awesome, thanks!!
Who is online
Users browsing this forum: No registered users and 6 guests