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

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

本文关键字:xaml 多边形 PointCollection cpp 实例化      更新时间:2023-10-16

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

在 .xaml 中创建画布和多边形的位置

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

将点集合传递到.cpp中的"多边形三角形"

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 ^

错误意味着三角形的类型>点和不对应,所以你应该转换的类型:

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;