【问题标题】:I would like to move a button based on a joint position with Kinect v2我想使用 Kinect v2 根据关节位置移动按钮
【发布时间】:2015-05-24 17:26:57
【问题描述】:

我的意图是使用 Kinect v2 跟踪关节,然后根据该关节位置在 Canvas 中移动按钮。 我的问题是按钮:它们不会移动并保持静止

这是我的代码:

if (joint.JointType == JointType.SpineMid) {
    ColorSpacePoint space =
    this.kinectRegion.KinectSensor.CoordinateMapper.MapCameraPointToColorSpace(joint.Position);
    Point center = new Point(space.X, space.Y);
    Point[] verticies = Polygon.CalculateVertices(buttons.Count, radius,
                                                  startingAngle, center);

    int i = 0;
    foreach (var button in buttons)
    {
        choices.Add(verticies[i], button);
        i++;
    }

    foreach (var obj in choices)
    {
        Canvas.SetLeft(obj.Value, obj.Key.X);
        Canvas.SetTop(obj.Value, obj.Key.Y);
    }

    choices.Clear();

}

按钮在 MainWindow.xaml 文件中声明为:

<Button x:Name="button1" Panel.ZIndex="1" Height="200" Width="200" Margin="0,436,1712,444" Background="Aqua" Visibility="Hidden" RenderTransformOrigin="-1.02,0.565" />
<Button x:Name="button2" Panel.ZIndex="1" Height="200" Width="200" Margin="927,10,785,870" Background="Aqua" Visibility="Hidden" RenderTransformOrigin="-1.02,0.565" />
<Button x:Name="button3" Panel.ZIndex="1" Height="200" Width="200" Margin="927,849,785,31" Background="Aqua" Visibility="Hidden" RenderTransformOrigin="-1.02,0.565" />
<Button x:Name="button4" Panel.ZIndex="1" Height="200" Width="200" Margin="1702,436,10,444" Background="Aqua" Visibility="Hidden" RenderTransformOrigin="-1.02,0.565" />

<Button x:Name="backButton" Visibility="Visible" Grid.Column="0" Style="{StaticResource BackButtonStyle}" Click="GoBack" />

verticies 包含按钮的点。 选择是:Dictionary&lt;Point, Button&gt; choices = new Dictionary&lt;Point,Button&gt;();

【问题讨论】:

  • 请格式化您的代码,以便人们可以真正阅读它。
  • "Specified element is already the logical child of another element. Disconnect it first" 看起来很简单。您需要先从当前放置的按钮中删除按钮,然后再将其添加到另一个按钮。它永远不可能有两个父母。

标签: c# wpf button kinect


【解决方案1】:

为什么要将按钮再次放入Canvas?您可以简单地更改它们的 Canvas.LeftCanvas.Top 属性,它们就会被移动。

【讨论】:

  • 你是对的,我已经删除了我项目中的那部分代码。现在我正在编辑上面的代码
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-03-14
  • 1970-01-01
  • 2012-07-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多