jc_lvngstn
Topic Author
Posts: 34
Joined: 23 Sep 2013, 03:03

My property notifier implementation

07 Oct 2013, 15:53

I was able to get this to work:
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:
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?
 
User avatar
sfernandez
Site Admin
Posts: 3197
Joined: 22 Dec 2011, 19:20

Re: My property notifier implementation

07 Oct 2013, 23:40

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.
 
jc_lvngstn
Topic Author
Posts: 34
Joined: 23 Sep 2013, 03:03

Re: My property notifier implementation

07 Oct 2013, 23:52

That sounds awesome, thanks!!

Who is online

Users browsing this forum: No registered users and 6 guests