Passing Rectangle via converter
Posted: 28 Aug 2021, 01:26
Hello,
I am currently trying to pass a Rectangle in to a convert so that I can return a Rect for a Viewbox. Unfortuantely, I am missing something simple when trying to either cast or Unbox the BaseComponent*.
When attempting to unbox the Rectangle I get the follow error:
Here is the code in the converter:
I am currently trying to pass a Rectangle in to a convert so that I can return a Rect for a Viewbox. Unfortuantely, I am missing something simple when trying to either cast or Unbox the BaseComponent*.
When attempting to unbox the Rectangle I get the follow error:
What may I be doing wrong here?'Project.UI.Converters.ElementPositionSizeConverter' binding converter failed to convert value 'Rectangle' (type 'Rectangle')'Project.UI.Converters.ElementPositionSizeConverter' binding converter failed to convert value 'Rectangle' (type 'Rectangle')
Here is the code in the converter:
Code: Select all
bool ElementPositionSizeConverter::TryConvert(Noesis::BaseComponent* value, const Noesis::Type* /*targetType*/, Noesis::BaseComponent* /*parameter*/, Noesis::Ptr<Noesis::BaseComponent>& result)
{
if (Noesis::Boxing::CanUnbox<Noesis::Rectangle*>(value))
{
const Noesis::Rectangle* myRectangle = Noesis::Boxing::Unbox<Noesis::Rectangle*>(value);
if (myRectangle)
{
Noesis::Size contentSize = Noesis::Size(myRectangle->GetActualWidth(), myRectangle->GetActualHeight());
const Noesis::Point contentPosition = (myRectangle->PointToScreen(Noesis::Point(0, 0)));
result.Reset(Noesis::Boxing::Box(Noesis::Rect(contentPosition, contentSize)));
return true;
}
}
return false;
}