-
- jc_lvngstn
- Posts: 34
- Joined:
Dynamically adding a usercontrol.
I'm having trouble dynamically adding a user control to an existing panel.
I have the main panel defined below. All it is is a stackpanel names WindowList. I want to add the user control to this stackpanel.
Here is the xaml for my user control:
Again, pretty simple. Just a stackpanel with a button.
Here is the code behind for the main panel:
You can see that I am executing ShowInventory() when the "Show UserControl" button is clickked. It's adding it to the _WindowList (the stackpanel in the main UI) children. By the way, the Debug is correctly showing that the stackpanel is being identified correctly in my output.
Here is the code for the TestWindow usercontrol.
What happens when I actually click on the Add UserControl button is this:
ApplicationException: Unity/Unity/_Game/NoesisUI/TestWindow.xaml resource not found
Noesis.Collection.Add (Noesis.BaseComponent item) (at Assets/Plugins/NoesisGUI/Scripts/Proxies/Collection.cs:90)
TestController.ShowInventory () (at Assets/_Game/NoesisUI/TestController.cs:35)
TestController.ShowInvButtonOnClick (Noesis.BaseComponent arg0, Noesis.RoutedEventArgs routedEventArgs) (at Assets/_Game/NoesisUI/TestController.cs:30)
Noesis.BaseButton.RaiseClick (IntPtr cPtr, IntPtr arg0, IntPtr arg1) (at Assets/Plugins/NoesisGUI/Scripts/Proxies/BaseButton.cs:102)
(wrapper native-to-managed) Noesis.BaseButton:RaiseClick (intptr,intptr,intptr)
Noesis.UIRenderer.Noesis_MouseButtonUp (Int32 rendererId, Single x, Single y, Int32 button) (at Assets/Plugins/NoesisGUI/Scripts/Core/NoesisUIRendererImports.cs:168)
Noesis.UIRenderer.ProcessEvent (UnityEngine.Event ev) (at Assets/Plugins/NoesisGUI/Scripts/Core/NoesisUIRenderer.cs:205)
NoesisGUIPanel.OnGUI () (at Assets/Plugins/NoesisGUI/Scripts/NoesisGUIPanel.cs:134)
It's odd that it shows it is looking in Unity/Unity/_Game/Noes... location. I have verified that the usercontrol is in the correct folder.
Any thoughts/suggestions on this? If this is a bit confusing to decipher, a small, simple example of how to have a single main panel, with dynamically added user controls would be very useful. It doesn't have to be complex, just very simple controls for speed's sake
Thank you,
JC
I have the main panel defined below. All it is is a stackpanel names WindowList. I want to add the user control to this stackpanel.
Code: Select all
<DockPanel
Name="ContainerDockPanel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:UserControls="clr-namespace:UserControls" mc:Ignorable="d" MaxWidth="500" Height="300" MinHeight="110">
<DockPanel.RenderTransform>
<TranslateTransform X="0" Y="0"/>
</DockPanel.RenderTransform>
<StackPanel Name="WindowList">
<Button Name="ShowUserControl">Show UserControl</Button>
</StackPanel>
</DockPanel>
Code: Select all
<UserControl Name="TestWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel>
<Button>User Control!</Button>
</StackPanel>
</UserControl>
Here is the code behind for the main panel:
Code: Select all
public class TestController : MonoBehaviour
{
private NoesisGUIPanel _uiPanel;
private FrameworkElement _Root;
private Button _ShowInvButton;
private StackPanel _WindowList;
private DockPanel _DockPanel;
// Use this for initialization
private void Start()
{
_uiPanel = NoesisGUISystem.GetPanel("TestController");
_Root = _uiPanel.GetRoot<FrameworkElement>();
_DockPanel = _Root.FindName<DockPanel>("ContainerDockPanel");
_ShowInvButton = _Root.FindName<Button>("ShowUserControl");
Debug.Log(_ShowInvButton.GetName());
_ShowInvButton.Click += ShowInvButtonOnClick;
_WindowList = _DockPanel.FindName<StackPanel>("WindowList");
Debug.Log(_WindowList.GetName());
}
private void ShowInvButtonOnClick(BaseComponent arg0, RoutedEventArgs routedEventArgs)
{
ShowInventory();
}
private void ShowInventory()
{
_WindowList.GetChildren().Add(new TestWindow());
}
}
Here is the code for the TestWindow usercontrol.
Code: Select all
namespace UserControls
{
public class TestWindow : UserControl
{
private HandleRef swigCPtr;
public static void Register()
{
// Override the source to indicate the user control xaml
UserControl.SourceProperty.OverrideMetadata(typeof(TestWindow),
new PropertyMetadata("Assets/_Game/NoesisUI/TestWindow.xaml"));
}
public TestWindow(IntPtr cPtr, bool cMemoryOwn)
: base(cPtr, cMemoryOwn)
{
swigCPtr = new HandleRef(this, cPtr);
}
public TestWindow()
: this(Noesis.Extend.New(typeof(TestWindow)), true)
{
Noesis.Extend.Register(typeof(TestWindow), swigCPtr.Handle, this);
}
public override void Dispose()
{
lock (this)
{
if (swigCPtr.Handle != IntPtr.Zero)
{
if (swigCMemOwn)
{
swigCMemOwn = false;
if (Kernel.IsInitialized())
{
Noesis.Extend.Delete(typeof(TestWindow), swigCPtr.Handle);
}
}
swigCPtr = new HandleRef(null, IntPtr.Zero);
}
GC.SuppressFinalize(this);
base.Dispose();
}
}
}
}
What happens when I actually click on the Add UserControl button is this:
ApplicationException: Unity/Unity/_Game/NoesisUI/TestWindow.xaml resource not found
Noesis.Collection.Add (Noesis.BaseComponent item) (at Assets/Plugins/NoesisGUI/Scripts/Proxies/Collection.cs:90)
TestController.ShowInventory () (at Assets/_Game/NoesisUI/TestController.cs:35)
TestController.ShowInvButtonOnClick (Noesis.BaseComponent arg0, Noesis.RoutedEventArgs routedEventArgs) (at Assets/_Game/NoesisUI/TestController.cs:30)
Noesis.BaseButton.RaiseClick (IntPtr cPtr, IntPtr arg0, IntPtr arg1) (at Assets/Plugins/NoesisGUI/Scripts/Proxies/BaseButton.cs:102)
(wrapper native-to-managed) Noesis.BaseButton:RaiseClick (intptr,intptr,intptr)
Noesis.UIRenderer.Noesis_MouseButtonUp (Int32 rendererId, Single x, Single y, Int32 button) (at Assets/Plugins/NoesisGUI/Scripts/Core/NoesisUIRendererImports.cs:168)
Noesis.UIRenderer.ProcessEvent (UnityEngine.Event ev) (at Assets/Plugins/NoesisGUI/Scripts/Core/NoesisUIRenderer.cs:205)
NoesisGUIPanel.OnGUI () (at Assets/Plugins/NoesisGUI/Scripts/NoesisGUIPanel.cs:134)
It's odd that it shows it is looking in Unity/Unity/_Game/Noes... location. I have verified that the usercontrol is in the correct folder.
Any thoughts/suggestions on this? If this is a bit confusing to decipher, a small, simple example of how to have a single main panel, with dynamically added user controls would be very useful. It doesn't have to be complex, just very simple controls for speed's sake

Thank you,
JC
-
- ai_enabled
- Posts: 231
- Joined:
- Contact:
Re: Dynamically adding a usercontrol.
Looks like you forgot to point on class (x:Class="UserControls.TestWindow") in XAML:
try to add this and click "Build" in Unity: menu Windows -> NoesisGUI -> Settings.
Code: Select all
<UserControl Name="TestWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="UserControls.TestWindow">
<StackPanel>
<Button>User Control!</Button>
</StackPanel>
</UserControl>
AtomicTorch Studio Pte. Ltd. http://atomictorch.com
-
- jc_lvngstn
- Posts: 34
- Joined:
Re: Dynamically adding a usercontrol.
Oh my crap! It worked! I could have sworn I tried that and got partial class errors, but it worked

Thank you!


Thank you!
Re: Dynamically adding a usercontrol.
The "Unity/Unity/" is internal and should never appear. It should say "Assets/_Game/..".It's odd that it shows it is looking in Unity/Unity/_Game/Noes... location. I have verified that the usercontrol is in the correct folder.
Will be fixed in the next release.
Hmm.. curious about this. Doesn't the xaml rebuild automatically when you edit it?try to add this and click "Build" in Unity: menu Windows -> NoesisGUI -> Settings.
-
- jc_lvngstn
- Posts: 34
- Joined:
Re: Dynamically adding a usercontrol.
Mine seems to rebuild consistently on its own.
By the way...I just want to say how excited I am with NoesisGUI so far. I've gotten my main canvas up, I'm dynamically adding windows, closing them, moving them around, etc. I'm very excited, and the level of support on this forum has definitely helped!
By the way...I just want to say how excited I am with NoesisGUI so far. I've gotten my main canvas up, I'm dynamically adding windows, closing them, moving them around, etc. I'm very excited, and the level of support on this forum has definitely helped!
-
- ai_enabled
- Posts: 231
- Joined:
- Contact:
Re: Dynamically adding a usercontrol.
Sometimes it's required to click build, sometimes not. We don't know why. And for our big project (~100 usercontrols) NoesisGUI build tool like to crash Unity in 75% of attempts (and Editor.log doesn't contain any error messages). We found workaround - force Unity to reimport folder with XAML's. It doesn't crash so oftenHmm.. curious about this. Doesn't the xaml rebuild automatically when you edit it?try to add this and click "Build" in Unity: menu Windows -> NoesisGUI -> Settings.

Also we going crazy about Unity freezes and crashes when we stop play mode in Unity.
Hope the NoesisGUI 1.0.5 release will fix some of this issues.
AtomicTorch Studio Pte. Ltd. http://atomictorch.com
Re: Dynamically adding a usercontrol.
Thanks! By the way, I sent you a private email.Mine seems to rebuild consistently on its own.
By the way...I just want to say how excited I am with NoesisGUI so far. I've gotten my main canvas up, I'm dynamically adding windows, closing them, moving them around, etc. I'm very excited, and the level of support on this forum has definitely helped!
Re: Dynamically adding a usercontrol.
Hi Vladimir, sorry to hear that. First notice I have that you are getting 75% of times crashes when you build. There is something totally wrong there. I have been using Unity + NoesisGUI for three days without having to reopen Unity. 0 crashes. I think that at your macroscopic scale (100+ usercontrols) new problems could be appearing. I wonder, could we (after signing a NDA) getting a copy of that project to investigate all your problems?Sometimes it's required to click build, sometimes not. We don't know why. And for our big project (~100 usercontrols) NoesisGUI build tool like to crash Unity in 75% of attempts (and Editor.log doesn't contain any error messages). We found workaround - force Unity to reimport folder with XAML's. It doesn't crash so often...
Also we going crazy about Unity freezes and crashes when we stop play mode in Unity.
Hope the NoesisGUI 1.0.5 release will fix some of this issues.
By the way, there won't be 1.0.5. Next version (we are finishing the last tests, if everything goes ok it will be in the servers tomorrow) is going to be 1.1.0 and brings a new and simplified API for UserControls. Now extending is a lot simpler. Apart from that and a lot more things, there are a few more bugfixed solved for you.
Please, remember, critical problems that go into our bugtracker receive high priority from our team.
Thanks
-
- golgepapaz
- Posts: 43
- Joined:
Re: Dynamically adding a usercontrol.
Well that's a relief.. Eagerly anticipating. I am guessing the tutorials will be updated/rewritten accordingly?
By the way, there won't be 1.0.5. Next version (we are finishing the last tests, if everything goes ok it will be in the servers tomorrow) is going to be 1.1.0 and brings a new and simplified API for UserControls. Now extending is a lot simpler.
Thanks
Re: Dynamically adding a usercontrol.
Yes, tutorials have been updated.Well that's a relief.. Eagerly anticipating. I am guessing the tutorials will be updated/rewritten accordingly?
Who is online
Users browsing this forum: No registered users and 31 guests