[英]I would like to move a button based on a joint position with Kinect v2
My intention is to track a joint with the Kinect v2, and then move a button in a Canvas based on that joint position. 我的意图是使用Kinect v2跟踪关节,然后根据该关节位置在“画布”中移动一个按钮。 My problem is the buttons: they don't move and stay still
我的问题是按钮:它们不会移动并保持静止
Here is my code: 这是我的代码:
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();
}
The buttons are declared in the MainWindow.xaml file as: 这些按钮在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 contains the point from the buttons. 顶点包含按钮中的点。 choices is:
Dictionary<Point, Button> choices = new Dictionary<Point,Button>();
选择是:
Dictionary<Point, Button> choices = new Dictionary<Point,Button>();
Why do you want to place the Buttons into Canvas
again? 您为什么要再次将“按钮”放到“
Canvas
? You can simply change their Canvas.Left
a Canvas.Top
properties and they will be moved. 您只需更改其
Canvas.Left
和Canvas.Top
属性即可将其移动。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.