CustomConverter: What is the target type of a DoubleAnimation targeting RenderTransform.X?
Posted: 11 Jan 2023, 13:49
Hey everyone,
simple question and maybe obvious to answer... but is it? As it is a DOUBLEAnimation, "double" seems to be obvious, but Noesis uses floats in C++ for performance reasons. So I would expect that "float" is the correct answer here. The error message hints towards "Int32" which makes sense because we target a pixel position in screen space. But it isn't?!
I am working on a DoubleAnimation to animate the RenderTransform.X of a ListBox. The way I do it works in a general WPF project, but I can't get it to run in c++. Clearly, my custom converter is the issue because I cannot figure out which type I need to "Noesis::Boxing::Box<>" my return value into. It always returns false with the message: " 'SomeCompany.VisualConcept.MVVM.View.ConvertIndexToRenderTransformX' binding converter failed to convert value '0' (type 'Int32')"
So what type do I need to box my return value into?
As you can see in the following code, I checked for many types, but none of the if conditions are ever true.
And for reference, the ListBox I am working on:
simple question and maybe obvious to answer... but is it? As it is a DOUBLEAnimation, "double" seems to be obvious, but Noesis uses floats in C++ for performance reasons. So I would expect that "float" is the correct answer here. The error message hints towards "Int32" which makes sense because we target a pixel position in screen space. But it isn't?!
I am working on a DoubleAnimation to animate the RenderTransform.X of a ListBox. The way I do it works in a general WPF project, but I can't get it to run in c++. Clearly, my custom converter is the issue because I cannot figure out which type I need to "Noesis::Boxing::Box<>" my return value into. It always returns false with the message: " 'SomeCompany.VisualConcept.MVVM.View.ConvertIndexToRenderTransformX' binding converter failed to convert value '0' (type 'Int32')"
So what type do I need to box my return value into?
As you can see in the following code, I checked for many types, but none of the if conditions are ever true.
Code: Select all
class ConvertIndexToRenderTransformX : public Noesis::BaseValueConverter
{
public:
bool TryConvert(Noesis::BaseComponent* value, const Noesis::Type* targetType, Noesis::BaseComponent* parameter,
Noesis::Ptr<Noesis::BaseComponent>& result) override
{
if (targetType == Noesis::TypeOf<bool>()) {
DEBUG_ERROR("bool");
}
if (targetType == Noesis::TypeOf<int8_t>()) {
DEBUG_ERROR("int8_t");
}
if (targetType == Noesis::TypeOf<int16_t>()) {
DEBUG_ERROR("int16_t");
}
if (targetType == Noesis::TypeOf<int32_t>()) {
DEBUG_ERROR("int32_t");
}
if (targetType == Noesis::TypeOf<int64_t>()) {
DEBUG_ERROR("int64_t");
}
if (targetType == Noesis::TypeOf<uint8_t>()) {
DEBUG_ERROR("uint8_t");
}
if (targetType == Noesis::TypeOf<uint16_t>()) {
DEBUG_ERROR("uint16_t");
}
if (targetType == Noesis::TypeOf<uint32_t>()) {
DEBUG_ERROR("uint32_t");
}
if (targetType == Noesis::TypeOf<uint64_t>()) {
DEBUG_ERROR("uint64_t");
}
if (targetType == Noesis::TypeOf<int>()) {
DEBUG_ERROR("int");
}
if (targetType == Noesis::TypeOf<signed int>()) {
DEBUG_ERROR("signed int");
}
if (targetType == Noesis::TypeOf<float>()) {
DEBUG_ERROR("Float");
}
if (targetType == Noesis::TypeOf<double>()) {
DEBUG_ERROR("double");
}
/*if (targetType == Noesis::TypeOf<short>()) {
DEBUG_ERROR("short");
}
if (targetType == Noesis::TypeOf<long>()) {
DEBUG_ERROR("long");
}*/
if (targetType == Noesis::TypeOf<char>()) {
DEBUG_ERROR("char");
}
if (targetType == Noesis::TypeOf<Noesis::String>()) {
DEBUG_ERROR("Noesis::String");
}
if (targetType == Noesis::TypeOf<Noesis::Symbol>()) {
DEBUG_ERROR("Noesis::Symbol");
}
if (targetType == Noesis::TypeOf<Noesis::Point>()) {
DEBUG_ERROR("Noesis::Point");
}
if (targetType == Noesis::TypeOf<Noesis::TransformGroup>()) {
DEBUG_ERROR("Noesis::TransformGroup");
}
if (targetType == Noesis::TypeOf<float>() &&
Noesis::Boxing::CanUnbox<int>(value)) {
result = Noesis::Boxing::Box<float>(static_cast<float>(Noesis::Boxing::Unbox<int>(value) * -10.0));
return true;
}
return false;
}
bool TryConvertBack(Noesis::BaseComponent* value, const Noesis::Type* targetType, Noesis::BaseComponent* parameter, Noesis::Ptr<Noesis::BaseComponent>& result) override
{
ASSERT_UNREACHABLE("ConvertIndexToRenderTransformX::TryConvertBack() Not yet implemented [Manuel]");
return false;
}
private:
NS_IMPLEMENT_INLINE_REFLECTION_(ConvertIndexToRenderTransformX, Noesis::BaseValueConverter, "SomeCompany.VisualConcept.MVVM.View.ConvertIndexToRenderTransformX")
};
Code: Select all
<ListBox x:Name="EpisodeList">
<ListBox.RenderTransform>
<TranslateTransform X="0" Y="0"/>
</ListBox.RenderTransform>
<ListBox.Resources>
<Storyboard x:Key="MoveAnimation">
<DoubleAnimation To="{Binding SelectedEpisodeIndex, Converter={StaticResource ConvertIndexToRenderTransformX}}" Storyboard.TargetProperty="RenderTransform.X" Storyboard.TargetName="EpisodeList" Duration="00:00:00.250000" FillBehavior="HoldEnd" IsAdditive="True" IsCumulative="True"/>
<DoubleAnimation To="{Binding SelectedEpisodeIndex, Converter={StaticResource ConvertIndexToRenderTransformY}}" Storyboard.TargetProperty="RenderTransform.Y" Storyboard.TargetName="EpisodeList" Duration="00:00:00.250000" FillBehavior="HoldEnd" IsAdditive="True" IsCumulative="True"/>
</Storyboard>
</ListBox.Resources>
<behaviors:Interaction.Triggers>
<behaviors:PropertyChangedTrigger Binding="{Binding SelectedEpisodeIndex}">
<behaviors:ControlStoryboardAction Storyboard="{StaticResource MoveAnimation}"/>
</behaviors:PropertyChangedTrigger>
</behaviors:Interaction.Triggers>
</ListBox>