Page 1 of 1

[Unity] StaticExtensions

Posted: 20 Nov 2014, 21:02
by MrHayato
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

Re: [Unity] StaticExtensions

Posted: 21 Nov 2014, 14:09
by sfernandez
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.

Re: [Unity] StaticExtensions

Posted: 24 Nov 2014, 23:27
by MrHayato
Great, this will work in the meantime! Is there plans to add proper statics so that we can use any static class?

Re: [Unity] StaticExtensions

Posted: 25 Nov 2014, 09:59
by sfernandez
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

Posted: 28 Nov 2014, 01:36
by MrHayato
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.

Re: [Unity] StaticExtensions

Posted: 01 Dec 2014, 13:44
by sfernandez
I was able to reproduce the problem with namespaces. We will fix it for the next release.
Thanks for reporting.

Re: [Unity] StaticExtensions

Posted: 01 Dec 2014, 23:00
by jsantos
Please, file a bug to track when the problem is solved.
Thanks.

Re: [Unity] StaticExtensions

Posted: 02 Dec 2014, 03:34
by MrHayato
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.