Orann
Topic Author
Posts: 5
Joined: 12 Dec 2014, 02:50

[Unity] v1.2 UserControls

05 Mar 2015, 05:03

Hey all,

I just upgraded to v1.2 and it seems there's a lot of undocumented changes to how UserControls work - Previously I was declaring a lot of controls like so:
[Noesis.Extended]
[Noesis.UserControlSource("Assets/GUI/Controls/control.xaml")]
public class CustomUserControlTest : Noesis.UserControl {


    public void OnPostInit()
    {
        someGridWithinTheControl = FindName<Grid>("ControlRootGrid");
        buttonInTheControl= FindName<Button>("ControlButton");

...
as was recommended here.

However this seems to have changed -there's no longer a Noesis.Extended property, and the FindName() method doesn't accept a generic type (which seems like a flat downgrade?).

It'd really help if you could let me know the v1.2 method for creating and using UserControls!
 
User avatar
ai_enabled
Posts: 221
Joined: 18 Jul 2013, 05:28
Contact:

Re: [Unity] v1.2 UserControls

05 Mar 2015, 05:09

Remove [Noesis.Extended] and use (Grid)FindName("ControlRootGrid") instead of FindName<Grid>("ControlRootGrid").
I've updated more than hundred of user controls on 1.2 and it was pretty easy (with regex replacement). Works well!
AtomicTorch Studio Pte. Ltd. http://atomictorch.com
 
Orann
Topic Author
Posts: 5
Joined: 12 Dec 2014, 02:50

Re: [Unity] v1.2 UserControls

05 Mar 2015, 05:52

Remove [Noesis.Extended] and use (Grid)FindName("ControlRootGrid") instead of FindName<Grid>("ControlRootGrid").
I've updated more than hundred of user controls on 1.2 and it was pretty easy (with regex replacement). Works well!
It shouldn't be too hard to change them all, but it seems like a strange change to me - the generic argument was convenient and fit well into the native C# way of things - Noesis staff, any word on why it was removed?
Also, if this is the accepted solution, updating the documentation to fit would be very helpful for others like me - I can provide the changed code if it speeds things up for you.

Thanks for the help ai_enabled.
 
User avatar
ai_enabled
Posts: 221
Joined: 18 Jul 2013, 05:28
Contact:

Re: [Unity] v1.2 UserControls

05 Mar 2015, 06:09

NoesisGUI 1.2 introduced the new API replicating WPF. So you can prototype WPF application with Visual Studio/Blend and then copy-paste not only XAML, but also code to Unity and use it with a minimal changes for NoesisGUI. I really like this way, as 1.1 API was much different in some aspects and it was hard to maintain two versions of codebase - for the WPF prototype and the game...

But I agree with you that generic methods was really helpful (I mean methods FindName<T>() and GetStringResource<T>()). You can restore them easily, as C# API of NoesisGUI is extendable (and your changes will be not overwritten with the next NoesisGUI update).

So if you want to restore generic FindName<T> you need to:
1. create folder inside Plugins dir with name "NoesisGUI_Extensions" (or any other name you like)
2. add a file into it with name "FrameworkElementCustomExtend.cs" (I like this name)
3. put this code into the file:
namespace Noesis
{
	using System;

	public partial class FrameworkElement
	{
		#region Public Methods and Operators

		public T FindName<T>(string name) where T : BaseComponent
		{
			return this.FindName(name) as T;
		}

		public T FindStringResource<T>(string name) where T : BaseComponent
		{
			return this.FindStringResource(name) as T;
		}

		#endregion
	}
}
Regards!
AtomicTorch Studio Pte. Ltd. http://atomictorch.com
 
User avatar
jsantos
Site Admin
Posts: 2907
Joined: 20 Jan 2012, 17:18
Contact:

Re: [Unity] v1.2 UserControls

05 Mar 2015, 06:43

Exactly. We did this change to replicate WPF API. That way sharing code between our framework and WPF is easier. You can still have v1.1 convenient API by doing what ai_enabled explained above or using extensions methods. I would say this way is a bit better.
public static class NoesisExtensions
{

  public static T FindName<T>(this Noesis.FrameworkElement element, string name)
  {
      return (T)element.FindName(name);
  }

}
Regarding the documentation, our User Control Tutorial and Custom Control Tutorial are yet not updated. Sorry for that, we were waiting for a feature (code behind event handlers) that at the end was not incorporated into v1.2, the same happened with that documentation. We are working on it.

Thanks for your feedback!
 
Orann
Topic Author
Posts: 5
Joined: 12 Dec 2014, 02:50

Re: [Unity] v1.2 UserControls

05 Mar 2015, 07:08

Thanks for the help!

As the documentation hadn't changed, and I hadn't seen this mentioned anywhere around here, I was worried it was an import error of some kind. Given how heavily I tend to use UserControls, i'm surprised there's not more discussion on them around here in general.

Thanks for the hard work on v1.2!

Who is online

Users browsing this forum: No registered users and 0 guests