如何将 .cpp 中实例化的 PointCollection 传递给 .xaml 中的多边形?

How do you pass a PointCollection instantiated in a .cpp to a Polygon in an .xaml?

我正在尝试使用用户提供的值在 canvas 中绘制多边形。给定 .xaml 中的默认值,渲染效果很好。我的问题出现在尝试从 .cpp 设置多边形点 属性 的值时。我是 UWP 的超级新手,我想我可以将 Points 设置为等于 PointCollection,但这似乎不起作用。任何帮助都会很棒

其中 Canvas 和多边形创建于 .xaml

<Canvas x:Name="tCan" Margin="396,48,88,146">
       <Polygon x:Name="triangle" Stroke="Black"/>
</Canvas>

在 .cpp

中将 PointCollection 传递给 'Polygon triangle'
By = 100 + a;
Cy = ((a * a) + (c * c) - (b * b)) / (2 * a);
Cx = sqrt((c * c - (Cy * Cy)));

PointCollection points;
points.Append(Point(100, 100));
points.Append(Point(100, By));
points.Append(Point(Cx, Cy));

triangle->Points = points;

最后一行抛出

"Windows::UI::Xaml::Shapes::Polygon::Points::set" cannot be called with the given argument list  
argument types are: (Windows::UI::Xaml::Media::PointCollection)  
object type is: Windows::UI::Xaml::Shapes::Polygon ^

报错是指triangle->Pointspoints的类型不对应,需要转换[=的类型13=]分 :

By = 100 + a;
Cy = ((a * a) + (c * c) - (b * b)) / (2 * a);
Cx = sqrt((c * c - (Cy * Cy)));

PointCollection^ points = ref new PointCollection();
points->Append(Point(100, 100));​
points->Append(Point(100, By));​
points->Append(Point(Cx, Cy));​

​triangle->Points = points;