How to convert a String in NoesisXaml and then show it on Screen
Title says it allready.
i do some tests with Noesisi and try to lean in the moment WPF myshelf.
i have a string like wich have xaml code in it like the sample below, wich i want to show on the screen. can someone give me a Piece of code wich will do the work?
i have allready try the last two days what i can do and in the moment the most easy way to archive the goal is to convert it in a file and then let Noesis.GUI.LoadComponent() do the work maybe.
i do some tests with Noesisi and try to lean in the moment WPF myshelf.
i have a string like wich have xaml code in it like the sample below, wich i want to show on the screen. can someone give me a Piece of code wich will do the work?
i have allready try the last two days what i can do and in the moment the most easy way to archive the goal is to convert it in a file and then let Noesis.GUI.LoadComponent() do the work maybe.
Code: Select all
string XamlToRead = @"<UserControl x:Name=""BackgroundWindowRoot"" x:Class=""WPFvStageStyle.Background""
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
xmlns:mc=""http://schemas.openxmlformats.org/markup-compatibility/2006""
xmlns:d=""http://schemas.microsoft.com/expression/blend/2008""
xmlns:local=""clr-namespace:WPFvStageStyle""
xmlns:noesis=""clr-namespace:NoesisGUIExtensions;assembly=Noesis.GUI.Extensions""
mc:Ignorable=""d""
d:DataContext=""{d:DesignInstance {x:Type local:ViewModel}, IsDesignTimeCreatable=True}""
d:DesignHeight=""1080"" d:DesignWidth=""1920""
>
<Grid>
<!-- Background & Vignette-->
<Canvas x:Name=""Background_Color"" Background=""#FF272727"">
</Canvas>
<Canvas x:Name=""Background_Vignette"">
<Canvas.Background>
<RadialGradientBrush>
<GradientStop/>
<GradientStop Color = ""#00000000"" Offset=""0.0""/>
<GradientStop Color = ""#19000000"" Offset=""0.5""/>
<GradientStop Color = ""#66000000"" Offset=""1""/>
</RadialGradientBrush>
</Canvas.Background>
</Canvas>
</Grid>
</UserControl>" ;
-
sfernandez
Site Admin
- Posts: 3154
- Joined:
Re: How to convert a String in NoesisXaml and then show it on Screen
Hi,
Calling Noesis.GUI.ParseXaml(xamlText) will load an UI from a xaml text. The returned object can be added to an existing UI tree, for example you can have a simple xaml with a root Grid attached to your main camera, and then do the following in a MonoBehavior:
Is that what your are looking for?
Calling Noesis.GUI.ParseXaml(xamlText) will load an UI from a xaml text. The returned object can be added to an existing UI tree, for example you can have a simple xaml with a root Grid attached to your main camera, and then do the following in a MonoBehavior:
Code: Select all
NoesisView view = GetComponent<NoesisView>();
Noesis.Grid grid = (Noesis.Grid)view.Content;
grid.Children.Add((Noesis.UserControl)Noesis.GUI.ParseXaml(xamlText));
Re: How to convert a String in NoesisXaml and then show it on Screen
i can guess in wich direction this is going thanks.
sadly i get a error now: hope i can solve it somehow and will write here again
sadly i get a error now: hope i can solve it somehow and will write here again
Last edited by Noa3 on 01 Oct 2020, 13:08, edited 1 time in total.
-
sfernandez
Site Admin
- Posts: 3154
- Joined:
Re: How to convert a String in NoesisXaml and then show it on Screen
First you need a xaml file like this:
Then drag the generated xaml asset to the Main camera gameobject and it will automatically create a NoesisView component on the camera to render that xaml.
Next attach your TestNoesis_ReadXamlString MonoBehavior to the Main camera too.
That should work.
Code: Select all
<Grid
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
</Grid>
Next attach your TestNoesis_ReadXamlString MonoBehavior to the Main camera too.
That should work.
Re: How to convert a String in NoesisXaml and then show it on Screen
Thank for your time, works fine now.
the problem was the simple placeholder xaml file was not a Grid .
is there a soulution without a "placeholder" file or should i cretae a ticket maybe for it?
the problem was the simple placeholder xaml file was not a Grid .
is there a soulution without a "placeholder" file or should i cretae a ticket maybe for it?
Re: How to convert a String in NoesisXaml and then show it on Screen
All is working now in Unity, thanks!
if i put in the method AddContentOverCreatedXaml now a xaml string, i dont even need a dummy fille anymore.
if i put in the method AddContentOverCreatedXaml now a xaml string, i dont even need a dummy fille anymore.
Code: Select all
static string FileName = "sammplesXaml.xaml";
string unityPath = "/tmp/";
string FilePath = "";
string PathFull
{
get
{
return FilePath + unityPath + FileName;
}
}
void AddContentOverCreatedXaml(string XamlStringToLoad)
{
NoesisXaml nx = new NoesisXaml();
NoesisView view = GetComponent<NoesisView>();
WriteXamlDummyFile();
nx.source = PathFull;
nx.content = StringToByteArray(XamlStringToLoad);
nx.Load();
view.Xaml = nx;
view.LoadXaml(true);
}
private void WriteXamlDummyFile()
{
if (Directory.Exists(FilePath + unityPath) == false)
{
Directory.CreateDirectory(FilePath + unityPath);
}
System.IO.File.WriteAllText(PathFull, XamlToRead);
}
Re: How to convert a String in NoesisXaml and then show it on Screen
Thanks for the feedback! Marking this as solved
Who is online
Users browsing this forum: Ahrefs [Bot], Killian and 0 guests