Page 1 of 1

Converter to get TYPE and compare with x:Type

Posted: 19 May 2022, 15:10
by MarkSim
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.

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

Posted: 20 May 2022, 11:43
by sfernandez
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")
};

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

Posted: 23 May 2022, 12:46
by MarkSim
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.