【问题标题】:How do you pass a PointCollection instantiated in a .cpp to a Polygon in an .xaml?如何将 .cpp 中实例化的 PointCollection 传递给 .xaml 中的 Polygon?
【发布时间】:2019-06-22 05:00:15
【问题描述】:

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

Canvas 和 Polygon 在 .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 ^

【问题讨论】:

    标签: c++ xaml canvas uwp polygon


    【解决方案1】:

    该错误表示triangle->Points和points的类型不对应,所以你应该转换points的类型:

    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;
    

    【讨论】:

      猜你喜欢
      • 2018-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多