MarkSim
Topic Author
Posts: 30
Joined: 20 Apr 2021, 18:59

Problem with custom "SwitchConverter" and Static Resources

24 Sep 2021, 10:53

I've implemented a "SwitchConverter" that allows me to do things like this:
<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>
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?
 
User avatar
sfernandez
Site Admin
Posts: 2983
Joined: 22 Dec 2011, 19:20

Re: Problem with custom "SwitchConverter" and Static Resources

24 Sep 2021, 11:28

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?
 
MarkSim
Topic Author
Posts: 30
Joined: 20 Apr 2021, 18:59

Re: Problem with custom "SwitchConverter" and Static Resources

24 Sep 2021, 11:51

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.
 
MarkSim
Topic Author
Posts: 30
Joined: 20 Apr 2021, 18:59

Re: Problem with custom "SwitchConverter" and Static Resources

24 Sep 2021, 11:54

Ah, sorry, just spotted there is a SetNodeParent.. !
 
MarkSim
Topic Author
Posts: 30
Joined: 20 Apr 2021, 18:59

Re: Problem with custom "SwitchConverter" and Static Resources

24 Sep 2021, 12:08

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

Re: Problem with custom "SwitchConverter" and Static Resources

24 Sep 2021, 12:25

When a class implements an interface you can use the NS_IMPLEMENT_INTERFACE_FIXUP macro to reimplement the base Interface methods.
class NS_GUI_CORE_API Animatable: public Freezable, public IUITreeNode
{
    ...
    NS_IMPLEMENT_INTERFACE_FIXUP

private:
    IUITreeNode* mOwner;
    NS_DECLARE_REFLECTION(Animatable, Freezable)
};
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.
As shown in my previous example code you'll need a new member in your class to keep the parent in the tree.
 
User avatar
sfernandez
Site Admin
Posts: 2983
Joined: 22 Dec 2011, 19:20

Re: Problem with custom "SwitchConverter" and Static Resources

24 Sep 2021, 12:51

We improved our Resources overview for next version to mention about the IUITreeNode requirement when using the C++ SDK.
 
MarkSim
Topic Author
Posts: 30
Joined: 20 Apr 2021, 18:59

Re: Problem with custom "SwitchConverter" and Static Resources

24 Sep 2021, 14:49

It doesn't seem to have worked unfortunately. Can I send you the code directly to make sure I'm not doing anything wrong?
 
User avatar
sfernandez
Site Admin
Posts: 2983
Joined: 22 Dec 2011, 19:20

Re: Problem with custom "SwitchConverter" and Static Resources

24 Sep 2021, 22:04

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.
 
MarkSim
Topic Author
Posts: 30
Joined: 20 Apr 2021, 18:59

Re: Problem with custom "SwitchConverter" and Static Resources

22 Oct 2021, 15:14

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.

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 66 guests