【问题标题】:Add path on rectangle element在矩形元素上添加路径
【发布时间】:2014-02-01 07:53:08
【问题描述】:

我有一个棋盘,我选择了UniformGrid 布局并用矩形填充它。现在,当我单击矩形时,我想在矩形上添加 Path 元素(棋子)。我怎么能做到这一点,因为矩形没有Children.Add() 方法。我也想知道当我再次点击时如何删除碎片。

【问题讨论】:

  • 在这里发布一些 XAML 代码。

标签: c# .net wpf grid add


【解决方案1】:

您必须将您的棋子放在UniformGrid 的顶部并手动计算它们的位置。例如,要将一块放在 b4 上,您可以尝试这样的操作:

<Grid>
   <UniformGrid></UniformGrid>
   <!-- Add piece paths here -->
</Grid> 


Path myChessPiece = new Path();
double lengthOfSquare = 24.0;
int positionX = 2;
int positionY = 4;

Canvas.SetTop(myChessPiece, positionY * lengthOfSquare);
Canvas.SetLeft(myChessPiece, positionX * lengthOfSquare);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-28
    • 2012-11-26
    • 2021-08-21
    • 1970-01-01
    • 2017-03-09
    • 1970-01-01
    • 2015-10-04
    • 1970-01-01
    相关资源
    最近更新 更多