[RECOVERED] Dynamic runtime xaml construction with modular windows
Our database got corrupted and we lost the content of this topic. Please, help us to recover this discussion.
Re: [RECOVERED] Dynamic runtime xaml construction with modular windows
I was seeking information on how to Enable and build a GUI through code,
Not using code behind, what would be the best integration for the base Xaml in Unity?
<usercontrol> or <grid>
Do they have pro's and cons?
one part was how to implement
I've been experiencing X:Class type errors, is there a naming convention or should I ditch it?
Not using code behind, what would be the best integration for the base Xaml in Unity?
<usercontrol> or <grid>
Do they have pro's and cons?
one part was how to implement
Code: Select all
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
d:DesignWidth="1280" d:DesignHeight="720">
<Grid>
</Grid>
</UserControl>
Last edited by digimbyte on 25 Nov 2018, 22:22, edited 2 times in total.
Re: [RECOVERED] Dynamic runtime xaml construction with modular windows
this is my base Xaml
Code: Select all
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
xmlns:noesis="clr-namespace:NoesisGUIExtensions"
x:Class="GUI.MainCanvas"
x:Name="MainCanvas"
d:DesignWidth="1280" d:DesignHeight="720"
FontFamily="Fonts/#WeblySleek UI Semilight">
<Grid x:Name="LayoutRoot" RenderTransformOrigin="0.5,0.5">
</Grid>
</UserControl>
-
sfernandez
Site Admin
- Posts: 2984
- Joined:
Re: [RECOVERED] Dynamic runtime xaml construction with modular windows
The x:Class attribute refers to the code-behind class corresponding to that xaml.
If you have an x:Class value of "GUI.MainCanvas" then you need to define that code-behind class like this:
If you have an x:Class value of "GUI.MainCanvas" then you need to define that code-behind class like this:
Code: Select all
using Noesis;
namespace GUI
{
public partial class MainCanvas : UserControl { ... }
}
-
sfernandez
Site Admin
- Posts: 2984
- Joined:
Re: [RECOVERED] Dynamic runtime xaml construction with modular windows
The same UI from a XAML can be built using only code.
Depending on how many children do you expect to add to the root element you will choose the type:
Depending on how many children do you expect to add to the root element you will choose the type:
- If only a single content will be added you can have a UserControl (ContentControl) as root, and you will set its Content property.
Code: Select all
UserControl root = new UserControl(); root.Content = new Button();
- If you plan to add many children, then you can choose any of the available Panels, for example a Grid. In this case you will use the Children property, and call Add() on the returned collection.
Code: Select all
Grid root = new Grid(); root.Children.Add(new Button()); root.Children.Add(new Ellipse { Fill = Brushes.Blue });
-
sfernandez
Site Admin
- Posts: 2984
- Joined:
Re: [RECOVERED] Dynamic runtime xaml construction with modular windows
To connect the UI created in code to the NoesisView component in Unity you would need a minimal xaml that will serve as the root of all your UI:
When you create that xaml inside Unity Assets folder an asset will be automatically generated. You can drag that asset into the Main Camera game object to create a NoesisView component which will load the root xaml. From a script attached to the Main Camera you can access the NoesisView and add all the UI elements you need:
This will render the created UI on top of the 3D scene.
Code: Select all
<Grid
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<!-- your UI will be added here -->
</Grid>
Code: Select all
using UnityEngine;
public LoadUIBehavior : MonoBehavior
{
void Start()
{
NoesisView view = GetComponent<NoesisView>();
Noesis.Grid root = (Noesis.Grid)view.Content;
root.Children.Add(new Button());
...
}
}
Re: [RECOVERED] Dynamic runtime xaml construction with modular windows
Thanks for the wonderful replies!
when the forums crashed, I lost this, and my work as my changes got corrupted
so I'm now able to catch up to where I was before
also, shouldn't that be
one last question, does NoesisGui integrate with Unity's GuiUtility?
such as set focus?
when the forums crashed, I lost this, and my work as my changes got corrupted
so I'm now able to catch up to where I was before
also, shouldn't that be
Code: Select all
Grid root = new Grid();
root.Children.Add(new Button());
root.Children.Add(new Ellipse { Fill = Brushes.Blue });
such as set focus?
-
sfernandez
Site Admin
- Posts: 2984
- Joined:
Re: [RECOVERED] Dynamic runtime xaml construction with modular windows
You are right, I fixed the typo, thanks.shouldn't that beCode: Select allGrid root = new Grid(); root.Children.Add(new Button()); root.Children.Add(new Ellipse { Fill = Brushes.Blue });
No, Noesis keeps track of its own focus.does NoesisGui integrate with Unity's GuiUtility?
such as set focus?
You can change it by calling Focus() on any UIElement.
Code: Select all
button.Focus();
Code: Select all
UIElement focused = root.Keyboard.FocusedElement;
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 7 guests