Accessing Style setters in Unity C#
What is the correct way to access the setter value strings in Unity C#?
<Style x:Key="SampleStyle" TargetType="{x:Type TextBlock}">
<Setter Property="FontWeight" Value="Regular"></Setter>
<Setter Property="FontSize" Value="18"></Setter>
</Style>
var style = FindResource<Noesis.Style>("SampleStyle");
var setters = style.GetSetters();
for (int i = 0; i < setters.Count(); i++)
{
var setter = setters.Get((uint)i).As<Setter>();
Debug.Log(string.Format("{0}: {1} {2}",setter.GetProperty().GetName(),setter.GetValue().GetType(), setter.GetTargetName()));
}
When I call setter.GetValue I get a Noesis.BaseComponent. I am interested in getting the value of 18 for font size in code.
Thanks
<Style x:Key="SampleStyle" TargetType="{x:Type TextBlock}">
<Setter Property="FontWeight" Value="Regular"></Setter>
<Setter Property="FontSize" Value="18"></Setter>
</Style>
var style = FindResource<Noesis.Style>("SampleStyle");
var setters = style.GetSetters();
for (int i = 0; i < setters.Count(); i++)
{
var setter = setters.Get((uint)i).As<Setter>();
Debug.Log(string.Format("{0}: {1} {2}",setter.GetProperty().GetName(),setter.GetValue().GetType(), setter.GetTargetName()));
}
When I call setter.GetValue I get a Noesis.BaseComponent. I am interested in getting the value of 18 for font size in code.
Thanks
-
-
sfernandez
Site Admin
- Posts: 3222
- Joined:
Re: Accessing Style setters in Unity C#
Hi,
Setter values are boxed inside a BaseComponent object. I'm sorry to tell current 1.1.12 API only allows to unbox strings, using the AsString() method:
We can add support for other basic types in a following release.
Anyway, the upcoming 1.2 version will deal with this in a transparent way, because we removed BaseComponent from the API, and everything is converted automatically from a to C# object, being able to do things like this:
Setter values are boxed inside a BaseComponent object. I'm sorry to tell current 1.1.12 API only allows to unbox strings, using the AsString() method:
Code: Select all
BaseComponent value = setter.GetValue();
Debug.Log(value.AsString());
Anyway, the upcoming 1.2 version will deal with this in a transparent way, because we removed BaseComponent from the API, and everything is converted automatically from a to C# object, being able to do things like this:
Code: Select all
float fontSize = setter.Value as float;
Who is online
Users browsing this forum: Google [Bot] and 3 guests