Problem with custom "SwitchConverter" and Static Resources
I've implemented a "SwitchConverter" that allows me to do things like this:
So basically, a switch statement. I use this for all sorts of things.
Problem is, when I port it to Noesis, it does not work and the inspector tells me that the static resources "True" and "False" are not found.
I have this same problem when using it for other things, like switching based on a list of pre-defined numbers.
Any idea what might be happening here?
Code: Select all
<sys:Boolean x:Key="True">True</sys:Boolean>
<sys:Boolean x:Key="False">False</sys:Boolean>
..
..
<Converters:SwitchConverter x:Key="BoolToVisibleOrHidden">
<Converters:SwitchCase When="{StaticResource True}" Then="Visible" />
<Converters:SwitchCase When="{StaticResource False}" Then="Hidden" />
</Converters:SwitchConverter>
Problem is, when I port it to Noesis, it does not work and the inspector tells me that the static resources "True" and "False" are not found.
I have this same problem when using it for other things, like switching based on a list of pre-defined numbers.
Any idea what might be happening here?
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: Problem with custom "SwitchConverter" and Static Resources
You are working with our C++ SDK, right? In that case I guess you are inheriting from BaseValueConverter to implement your own converter. As you can see that base class implements the IUITreeNode interface that the StaticResource uses to walk up the tree when searching for the resource. You should implement IUITreeNode interface also in the SwitchCase class, and use the UICollection to expose the list of switch cases. Could you try that?
Re: Problem with custom "SwitchConverter" and Static Resources
Yep I am using UICollection<SwitchCase>, however my SwitchCase inherits from DependencyObject - so I should also inherit from IUITreeNode, like this?
class SwitchCase : public Noesis::DependencyObject, public Noesis::IUITreeNode
I'm looking at the implementation of BaseValueConverter so I can implement the required functions, such as FIndNodeResource, etc. it refers to mOwner - how do I get that into my class? Sorry I'm probably being daft and missing something obvious.
class SwitchCase : public Noesis::DependencyObject, public Noesis::IUITreeNode
I'm looking at the implementation of BaseValueConverter so I can implement the required functions, such as FIndNodeResource, etc. it refers to mOwner - how do I get that into my class? Sorry I'm probably being daft and missing something obvious.
Re: Problem with custom "SwitchConverter" and Static Resources
Ah, sorry, just spotted there is a SetNodeParent.. !
Re: Problem with custom "SwitchConverter" and Static Resources
Okay, inheriting from IUITreeNode, I need to also implement AddReference, etc.. (everything in the Interface class) Can't help but think I am doing something wrong.
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: Problem with custom "SwitchConverter" and Static Resources
When a class implements an interface you can use the NS_IMPLEMENT_INTERFACE_FIXUP macro to reimplement the base Interface methods.
Code: Select all
class NS_GUI_CORE_API Animatable: public Freezable, public IUITreeNode
{
...
NS_IMPLEMENT_INTERFACE_FIXUP
private:
IUITreeNode* mOwner;
NS_DECLARE_REFLECTION(Animatable, Freezable)
};
As shown in my previous example code you'll need a new member in your class to keep the parent in the tree.I'm looking at the implementation of BaseValueConverter so I can implement the required functions, such as FIndNodeResource, etc. it refers to mOwner - how do I get that into my class? Sorry I'm probably being daft and missing something obvious.
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: Problem with custom "SwitchConverter" and Static Resources
We improved our Resources overview for next version to mention about the IUITreeNode requirement when using the C++ SDK.
Re: Problem with custom "SwitchConverter" and Static Resources
It doesn't seem to have worked unfortunately. Can I send you the code directly to make sure I'm not doing anything wrong?
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: Problem with custom "SwitchConverter" and Static Resources
Sure, please attach the definition and implementation of SwitchCase class and I'll take a look.
In the meantime you can try another approach, instead of implementing yourself that interface, inherit SwitchCase class from Animatable which already implements it.
In the meantime you can try another approach, instead of implementing yourself that interface, inherit SwitchCase class from Animatable which already implements it.
Re: Problem with custom "SwitchConverter" and Static Resources
I managed to get this working in the end, until I tried using a DynamicResource for the "Then" property. Again, works fine in WPF, null in Noesis :-(
I will check the source for Animatable to see if it differs from my SwitchCase implementation..
Let me know if there's anything else I should check though.
I will check the source for Animatable to see if it differs from my SwitchCase implementation..
Let me know if there's anything else I should check though.
Who is online
Users browsing this forum: Ahrefs [Bot], Semrush [Bot] and 70 guests