[Unity] StaticExtensions
Hi,
I'm trying to bring in some theming capabilities into our application, and we are thinking of using something along the lines of {x:Static Theming.PrimaryColor} to use the theming colors in our application. However, we're not sure how to get the statics defined. We've tried doing something like
as well as
But neither case worked when we tried to use it in our xaml. We keep getting a "Static value 's:BrandingStatic.TestColor' not found" error. According to the docs, the C++ library has a "IUISystem::SetStatic()" method to set the static, but I cannot find it in the Unity SDK. Is this something that isn't implemented in Unity yet, and is coming later? Or am I just doing it wrong?
Thanks
I'm trying to bring in some theming capabilities into our application, and we are thinking of using something along the lines of {x:Static Theming.PrimaryColor} to use the theming colors in our application. However, we're not sure how to get the statics defined. We've tried doing something like
Code: Select all
[Extended]
public static class BrandingStatics
{
static BrandingStatics()
{
Brushy = new SolidColorBrush(new Color(255, 0, 255, 255));
}
private static SolidColorBrush _brushy;
public static SolidColorBrush Brushy
{
get { return _brushy; }
set { _brushy = value; }
}
}
Code: Select all
[Extended]
public class BrandingStatic : SerializableComponent
{
//Note we need an instance so we can dynamically change the values dynamically
private static BrandingStatic _instance;
public static BrandingStatic Instance
{
get { return _instance ?? (_instance = new BrandingStatic()); }
}
public BrandingStatic()
{
Instance.SetTestColor(new SolidColorBrush(new Color(255, 0, 255, 255)));
}
private SolidColorBrush _testColor;
public void SetTestColor(SolidColorBrush brush)
{
_testColor = brush;
NotifyPropertyChanged("TestColor");
}
public static SolidColorBrush TestColor { get { return _instance._testColor; } }
}
Thanks
-
sfernandez
Site Admin
- Posts: 3184
- Joined:
Re: [Unity] StaticExtensions
Hi,
NoesisGUI only supports by now StaticExtensions for enum values (like in {x:Static Visibility.Hidden}).
We don't have support for accessing static properties from the XAML, neither for native nor managed objects.
We have a workaround for this limitation, we added the possibility of referencing DependencyProperties by using its default value as if it was the value of a static property, something like this:
If this doesn't fit your requirements you will need to bind to instance properties of a ViewModel.
NoesisGUI only supports by now StaticExtensions for enum values (like in {x:Static Visibility.Hidden}).
We don't have support for accessing static properties from the XAML, neither for native nor managed objects.
We have a workaround for this limitation, we added the possibility of referencing DependencyProperties by using its default value as if it was the value of a static property, something like this:
Code: Select all
[Extended]
public class Settings : BaseComponent
{
public static Noesis.DependencyProperty BaseColorProperty = Noesis.DependencyProperty.Register(
"BaseColor", typeof(SolidColorBrush), typeof(Settings), new PropertyMetadata(Brushes.DimGray()));
}
Code: Select all
<Grid.Resources>
<Style TargetType="Button">
<Setter Property="Background" Value="{x:Static Settings.BaseColor}"/>
</Style>
</Grid.Resources>
Re: [Unity] StaticExtensions
Great, this will work in the meantime! Is there plans to add proper statics so that we can use any static class?
-
sfernandez
Site Admin
- Posts: 3184
- Joined:
Re: [Unity] StaticExtensions
This feature was not included in our milestone, but if you find it essential for your project, you can add a new issue to our bugtracker to push its development, and we will study it
Re: [Unity] StaticExtensions
I just gave this a try, and it doesn't seem to work if there's a namespace for the class. Not sure if there's a workaround for this other than removing the namespace (I like namespaces!), but for now I'll leave the namespaces out and this works just fine.
-
sfernandez
Site Admin
- Posts: 3184
- Joined:
Re: [Unity] StaticExtensions
I was able to reproduce the problem with namespaces. We will fix it for the next release.
Thanks for reporting.
Thanks for reporting.
Re: [Unity] StaticExtensions
Please, file a bug to track when the problem is solved.
Thanks.
Thanks.
Re: [Unity] StaticExtensions
We're still working out the licensing with you guys, so I don't have an account that can log bugs yet. Sorry. I'll do it as soon as it's all worked out.
Who is online
Users browsing this forum: No registered users and 6 guests