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

Converter to get TYPE and compare with x:Type

19 May 2022, 15:10

Hi,
I've successfully made this converter in WPF: ObjectToTypeConverter
Which basically returns this: value.GetType()
Which allows me to do this:

<DataTrigger Binding="{Binding, Converter={StaticResource ObjectToType}}" Value="{x:Type vm:SomeViewModel}">

However I am having trouble making this work in Noesis. I've tried returning value->GetClassType(), and a few other ideas, but none seem to work. How can I do the equivalent?

EDIT: I have got round this by making an ObjectIsTypeConverter, where I use the converter parameter to pass the type I want to check against, and that is working fine - however I would still like to get this working.

Many thanks,
Mark.
 
User avatar
sfernandez
Site Admin
Posts: 2991
Joined: 22 Dec 2011, 19:20

Re: Converter to get TYPE and compare with x:Type

20 May 2022, 11:43

Hi, the converter should box the Type returned by the value:
struct ObjectToTypeConverter: BaseValueConverter
{
    bool TryConvert(BaseComponent* value, const Type*, BaseComponent*, Ptr<BaseComponent>& result) override
    {
        if (value != nullptr)
        {
            const Type* type = value->GetClassType();
            result = Boxing::Box(type);
            return true;
        }
        return false;
    }

    NS_IMPLEMENT_INLINE_REFLECTION_(ObjectToTypeConverter, BaseValueConverter, "SomeNamespace.ObjectToTypeConverter")
};
 
MarkSim
Topic Author
Posts: 30
Joined: 20 Apr 2021, 18:59

Re: Converter to get TYPE and compare with x:Type

23 May 2022, 12:46

I meant to say that I did try boxing it first. I will try again though, I may have missed something the first time round.

Who is online

Users browsing this forum: Semrush [Bot] and 4 guests