- KeldorKatarn
- Posts: 193
- Joined:
Question regarding x:class
So I found this tutorial video on your Youtube channel:
https://www.youtube.com/watch?v=50aPNUYSPyA&t=608s
It states that it is very important to remove the x:class attribute for a usercontrol that is used as the root element to work. Is this still the case?
I'm a bit confused about this because I now see some samples still using the attribute and code behind.
My basic questions:
- What was the problem with x:class in this tutorial exactly? Is that outdated?
- Is it now ok to keep x:class in any element or is it not allowed in the root element?
- If x:class was or is not allowed, how did or do custom user controls get referenced in other XAML. It's usually done by the class name and namespace, which isn't present without the x:class declaration.
I might be confused because of outdated info here, I have not been looking into Noesis in a while and just came back bringing myself up to date. So is my info outdated and x:class is now always ok? Should I keep the code generated code behind file now or should/can I still delete it?
I see people use code behind in their workflows now, using #if checks to make sure the correct namespaces are included in case unity compiles it insteas of it running against WPF. But is that code behind always needed? Is it allowed on the root element of the NoesisGUIPanel?
If this stuff is outdated maybe you guys should pull some of the old documentation. It's really confusing to figure out what the current API and workflow is.
https://www.youtube.com/watch?v=50aPNUYSPyA&t=608s
It states that it is very important to remove the x:class attribute for a usercontrol that is used as the root element to work. Is this still the case?
I'm a bit confused about this because I now see some samples still using the attribute and code behind.
My basic questions:
- What was the problem with x:class in this tutorial exactly? Is that outdated?
- Is it now ok to keep x:class in any element or is it not allowed in the root element?
- If x:class was or is not allowed, how did or do custom user controls get referenced in other XAML. It's usually done by the class name and namespace, which isn't present without the x:class declaration.
I might be confused because of outdated info here, I have not been looking into Noesis in a while and just came back bringing myself up to date. So is my info outdated and x:class is now always ok? Should I keep the code generated code behind file now or should/can I still delete it?
I see people use code behind in their workflows now, using #if checks to make sure the correct namespaces are included in case unity compiles it insteas of it running against WPF. But is that code behind always needed? Is it allowed on the root element of the NoesisGUIPanel?
If this stuff is outdated maybe you guys should pull some of the old documentation. It's really confusing to figure out what the current API and workflow is.
Re: Question regarding x:class
Bear in mind that I'm not an expert but...
Afaik, in that tutorial the code behind file was not used at all so that's why he removed x:class attribute.
If you want to use code behind then you obviously need to have the x:Class
in your xaml you need to have
We here at Dreamloop name our UserControls as root so it's easy to find and use in code behind.
and in your code behind file you need to have
obviously those lines with root things are not needed.
Afaik, in that tutorial the code behind file was not used at all so that's why he removed x:class attribute.
If you want to use code behind then you obviously need to have the x:Class
in your xaml you need to have
Code: Select all
<UserControl x:Class="My.Awesome.Namespace.MyAwesomeClass"
and in your code behind file you need to have
Code: Select all
namespace My.Awesome.Namespace
{
/// <summary>
/// Interaction logic for MyAwesomeClass.xaml
/// </summary>
[UserControlSource("Assets/My/Awesome/Path/To/Asset/MyAwesomeClass.xaml")]
public partial class MyAwesomeClass: UserControl
{
FrameworkElement _root;
public MyAwesomeClass()
{
this.Initialized += OnInitialized;
this.InitializeComponent();
}
private void OnInitialized(object sender, Noesis.EventArgs e)
{
_root = (UserControl)FindName("root");
}
}
}
- KeldorKatarn
- Posts: 193
- Joined:
Re: Question regarding x:class
Well considering he pointed out that it is VERY IMPORTANT to remove the attribute, it sounded like it wouldn't even work otherwise back then.
Also x:Class isn't just about code behind. As I mentioned, if I want to use a usercontrol not as the root but inside another XAML then I wouldn't know how without the x:class considering that's what's giving the control a class name that is used in the tag.
Also x:Class isn't just about code behind. As I mentioned, if I want to use a usercontrol not as the root but inside another XAML then I wouldn't know how without the x:class considering that's what's giving the control a class name that is used in the tag.
Re: Question regarding x:class
In our game editor .xaml, we have
And then we can just add what ever editors (UserControls) we have defined in our namespace to inside our game editor xaml.
Is this what you are after?
Code: Select all
<UserControl x:Class="Assets.GloryAssets.Scripts.GUI.UserControls.MainEditor"
xmlns:Editors="clr-namespace:Assets.GloryAssets.Scripts.GUI.UserControls"
...>
And then we can just add what ever editors (UserControls) we have defined in our namespace to inside our game editor xaml.
Is this what you are after?
- ai_enabled
- Posts: 231
- Joined:
- Contact:
Re: Question regarding x:class
KeldorKatarn, the x:Class attribute binds the XAML markup file with the according .XAML.CS code-behind class (so namespace+class name in the code-behind class must match).
If you're not going to use the code-behind in NoesisGUI, you should remove x:Class attribute from XAML.
If you're want to use the code-behind class, you need to keep the x:Class attribute and add to the code-behind class the UserControlSource attribute pointing on the XAML file.
So in case of reusable UserControl's you should keep x:Class and have according code-behind class with the proper UserControlSource attribute.
I think this was beyond the scope of the tutorial video so they didn't mentioned about it.
Regards!
If you're not going to use the code-behind in NoesisGUI, you should remove x:Class attribute from XAML.
If you're want to use the code-behind class, you need to keep the x:Class attribute and add to the code-behind class the UserControlSource attribute pointing on the XAML file.
So in case of reusable UserControl's you should keep x:Class and have according code-behind class with the proper UserControlSource attribute.
I think this was beyond the scope of the tutorial video so they didn't mentioned about it.
Regards!
AtomicTorch Studio Pte. Ltd. http://atomictorch.com
Re: Question regarding x:class
Sorry for the confusion about it and thanks everybody for helping here. Effectively, x:class is supported in NoesisGUI but for simplification purposes that Video Tutorial removed it.If this stuff is outdated maybe you guys should pull some of the old documentation. It's really confusing to figure out what the current API and workflow is.
I think we should remove that video entirely, because it is outdated. We are working these days in improving the documentation for v1.3, a preview of the Unity plugin is going to be released very soon. : )
Who is online
Users browsing this forum: Ahrefs [Bot] and 31 guests