SuperMax
Topic Author
Posts: 2
Joined: 01 Mar 2013, 11:58

unity3d and MVVM Binding

15 Apr 2013, 10:10

Hi,

I have experience in WPF and tried to use "NoesisGUI-0.9.8.4060" in unity3d with Binding in XAML.
I've tried to extend a "Tic-Tac-Toe" sample to work with Binding (MVVM).

I've created small ViewModel with public property "MyTxt":
public class MyVM : BaseComponent
{
		private HandleRef swigCPtr;
		
		// bindable prop
		public string MyTxt { get; set; }
		
		public static void Register()
	        {
	             BaseComponent.Extend_BaseComponent("MyVM", typeof(MyVM));
	        }
	
	    public MyVM(IntPtr cPtr, bool cMemoryOwn)
	        : base(cPtr, cMemoryOwn)
	    {
	        swigCPtr = new HandleRef(this, cPtr);
			
			// Init bindable prop
			MyTxt = "Hello World";
	    }
	
	    public MyVM()
	        : this(Noesis.Reflection.DoInstantiateExtend("MyVM"), true)
	    {
			Noesis.Reflection.DoSetExtendHandle("MyVM", swigCPtr.Handle, this);
	    }
	
	    public override void Dispose()
	    {
	        lock (this)
	        {
	            if (swigCPtr.Handle != IntPtr.Zero)
	            {
	                if (swigCMemOwn)
	                {
	                    swigCMemOwn = false;
	                    Noesis.Reflection.DoDeleteExtend("MyVM", swigCPtr.Handle);
	                }
	                swigCPtr = new HandleRef(null, IntPtr.Zero);
	            }
	            GC.SuppressFinalize(this);
	            base.Dispose();
	        }
	    }
};
In "NoesisRegisterClasses.cs" file, inside "Register" method I've added this line
MyVM.Register();
In "TicTacToe.cs" file, inside "Start" method, I've added this line:
this.mRoot.SetDataContext(new MyVM());
In "MainWindow.xaml" I've changed (563) line to work with binding:
<TextBlock x:Name="Title" Text="{Binding MyTxt}" ...
But, it seems that Binding isn't working or I did something wrong.
Please help :cry:

Thanks,
Maxim.
 
User avatar
sfernandez
Site Admin
Posts: 1918
Joined: 22 Dec 2011, 19:20

Re: unity3d and MVVM Binding

16 Apr 2013, 12:03

Notifications from DataContext objects were not correctly implemented in v0.9.8 yet, but are working on current version.

We will release a new version soon with many improvements to Unity data binding integration, following the suggestions from all of you.
 
SuperMax
Topic Author
Posts: 2
Joined: 01 Mar 2013, 11:58

Re: unity3d and MVVM Binding

16 Apr 2013, 15:11

Cool :)
I'll wait for this...

Who is online

Users browsing this forum: No registered users and 1 guest