MrHayato
Topic Author
Posts: 36
Joined: 19 Sep 2014, 21:29

[Unity] StaticExtensions

20 Nov 2014, 21:02

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
    [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; }
        }
    }
as well as
    [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; } }
    }
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
 
User avatar
sfernandez
Site Admin
Posts: 1911
Joined: 22 Dec 2011, 19:20

Re: [Unity] StaticExtensions

21 Nov 2014, 14:09

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:
[Extended]
public class Settings : BaseComponent
{
    public static Noesis.DependencyProperty BaseColorProperty = Noesis.DependencyProperty.Register(
        "BaseColor", typeof(SolidColorBrush), typeof(Settings), new PropertyMetadata(Brushes.DimGray()));
}
<Grid.Resources>
    <Style TargetType="Button">
        <Setter Property="Background" Value="{x:Static Settings.BaseColor}"/>
    </Style>
</Grid.Resources>
If this doesn't fit your requirements you will need to bind to instance properties of a ViewModel.
 
MrHayato
Topic Author
Posts: 36
Joined: 19 Sep 2014, 21:29

Re: [Unity] StaticExtensions

24 Nov 2014, 23:27

Great, this will work in the meantime! Is there plans to add proper statics so that we can use any static class?
 
User avatar
sfernandez
Site Admin
Posts: 1911
Joined: 22 Dec 2011, 19:20

Re: [Unity] StaticExtensions

25 Nov 2014, 09:59

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 ;)
 
MrHayato
Topic Author
Posts: 36
Joined: 19 Sep 2014, 21:29

Re: [Unity] StaticExtensions

28 Nov 2014, 01:36

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.
 
User avatar
sfernandez
Site Admin
Posts: 1911
Joined: 22 Dec 2011, 19:20

Re: [Unity] StaticExtensions

01 Dec 2014, 13:44

I was able to reproduce the problem with namespaces. We will fix it for the next release.
Thanks for reporting.
 
User avatar
jsantos
Site Admin
Posts: 2899
Joined: 20 Jan 2012, 17:18
Contact:

Re: [Unity] StaticExtensions

01 Dec 2014, 23:00

Please, file a bug to track when the problem is solved.
Thanks.
 
MrHayato
Topic Author
Posts: 36
Joined: 19 Sep 2014, 21:29

Re: [Unity] StaticExtensions

02 Dec 2014, 03:34

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 0 guests