[Unity] v1.2 UserControls
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:
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!
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:
Code: Select all
[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");
...
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!
-
- ai_enabled
- Posts: 221
- Joined:
- Contact:
Re: [Unity] v1.2 UserControls
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!
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
Re: [Unity] v1.2 UserControls
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?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!
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.
-
- ai_enabled
- Posts: 221
- Joined:
- Contact:
Re: [Unity] v1.2 UserControls
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:
Regards!
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:
Code: Select all
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
}
}
AtomicTorch Studio Pte. Ltd. http://atomictorch.com
Re: [Unity] v1.2 UserControls
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.
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!
Code: Select all
public static class NoesisExtensions
{
public static T FindName<T>(this Noesis.FrameworkElement element, string name)
{
return (T)element.FindName(name);
}
}
Thanks for your feedback!
Re: [Unity] v1.2 UserControls
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!
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 1 guest