Static Members / Singleton class
Hi guys
any update on 1305
I'm trying to see if its possible to use a Singleton class to easily import and deal with a huge amount of localised text in a dictionary
using some thing like:
It's a simple approach that works really well in Blend, but getting the 'not supported' message in Unity/Noesis.
do you have an idea, if and when you might get round to looking at it?
any update on 1305
I'm trying to see if its possible to use a Singleton class to easily import and deal with a huge amount of localised text in a dictionary
using some thing like:
Code: Select all
Content="{Binding Source={x:Static local:Translate.Instance}, Path=GameTexts[TXT_EXAMPLE_KEY]}
do you have an idea, if and when you might get round to looking at it?
-
sfernandez
Site Admin
- Posts: 2983
- Joined:
Re: Static Members / Singleton class
Hi Simon,
I'm sorry to say that we haven't implemented static members yet for the following release.
But as described in our documentation: https://www.noesisengine.com/docs/Gui.C ... cextension, there are some scenarios where x:Static already works and you can can use to workaround it. If you create a dependency property in your Translate class with the Instance as its default value, that will work in Noesis:
Can you try that?
I'm sorry to say that we haven't implemented static members yet for the following release.
But as described in our documentation: https://www.noesisengine.com/docs/Gui.C ... cextension, there are some scenarios where x:Static already works and you can can use to workaround it. If you create a dependency property in your Translate class with the Instance as its default value, that will work in Noesis:
Code: Select all
public class Translate
{
public static Translate Instance { get; } = new Translate();
public static readonly DependencyProperty InstanceProperty = DependencyProperty.Register(
"Instance", typeof(Translate), typeof(Translate), new PropertyMetadata(Translate.Instance));
...
}
Re: Static Members / Singleton class
Hi Sergio,
thanks for the work around. I have added the dependency object as written, but when I try and access it in XAML using my code above
VS gives the following error:
'Translate' type must derive from DependencyObject.
I tried having Translate inherit from Dependency object but it wont let me (Sealed class).
Am I missing some thing obvious?
thanks for the work around. I have added the dependency object as written, but when I try and access it in XAML using my code above
VS gives the following error:
'Translate' type must derive from DependencyObject.
I tried having Translate inherit from Dependency object but it wont let me (Sealed class).
Am I missing some thing obvious?
Re: Static Members / Singleton class
Ah never mind, figured it out.
That approach does work in Noesis/Unity but not in Blend were I was trying to test it.
Needed to ifdef it & make "Translate" a straightforward Singleton class in the WPF application.
thanks for the help :)
That approach does work in Noesis/Unity but not in Blend were I was trying to test it.
Needed to ifdef it & make "Translate" a straightforward Singleton class in the WPF application.
thanks for the help :)
-
sfernandez
Site Admin
- Posts: 2983
- Joined:
Re: Static Members / Singleton class
Hi Simon,
It works in Blend when running the project by using the static property, but I didn't notice before that in the designer the binding doesn't work once you add the dependency property with the same name. So as you said, this will require to ifdef the dependency property definition only for Noesis:
It works in Blend when running the project by using the static property, but I didn't notice before that in the designer the binding doesn't work once you add the dependency property with the same name. So as you said, this will require to ifdef the dependency property definition only for Noesis:
Code: Select all
public class Translate
{
public static Translate Instance { get; } = new Translate();
#if NOESIS
public static readonly DependencyProperty InstanceProperty = DependencyProperty.Register(
"Instance", typeof(Translate), typeof(Translate), new PropertyMetadata(Translate.Instance));
#endif
...
}
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 94 guests