我想根据与Kinect v2

时间:2015-05-24 17:26:58

标签: c# wpf button kinect

我的目的是跟踪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<Point, Button> choices = new Dictionary<Point,Button>();

1 个答案:

答案 0 :(得分:0)

为什么要再次将按钮放入Canvas?您只需更改其Canvas.LeftCanvas.Top属性即可移动它们。