我正在尝试使用用户提供的值在画布上绘制多边形。给定.xaml中的默认值,渲染效果很好。尝试从.cpp设置“多边形点”属性的值时出现我的问题。我是UWP的新手,我认为我可以将Point设置为等于PointCollection,但这似乎不起作用。任何帮助都很好
在.xaml中创建画布和多边形的地方
<Canvas x:Name="tCan" Margin="396,48,88,146">
<Polygon x:Name="triangle" Stroke="Black"/>
</Canvas>
将PointCollection传递到.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 ^
答案 0 :(得分:0)
该错误表示三角形->点和点的类型不对应,因此您应转换点的类型:< / p>
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;