LayoutRoot name does not exist in the current context

I am getting this erorr code: "The LayoutRoot name does not exist in the current context."

I haven't written any control in the Xaml file yet because I can't find the LayoutRoot control in the toolbox. How can I solve this problem?

This is my code:

using(SkeletonFrame frame = e.OpenSkeletonFrame())
{
if(frame != null)
{
Polyline figure;
Brush userBrush;
Skeleton skeleton;
**LayoutRoot.Children.Clear();**
frame.CopySkeletonDataTo(this._FrameSkeletons);
for(int i = 0; i < this._FrameSkeletons.Length; i++)
{
skeleton = this._FrameSkeletons[i];
if(skeleton.TrackingState == SkeletonTrackingState.Tracked)
{
userBrush = this._SkeletonBrushes[i % this._SkeletonBrushes.Length];
//Draws the skeleton’s head and torso
joints = new [] { JointType.Head, JointType.ShoulderCenter,
JointType.ShoulderLeft, JointType.Spine,
JointType.ShoulderRight, JointType.ShoulderCenter,
JointType.HipCenter, JointType.HipLeft,
JointType.Spine, JointType.HipRight,
JointType.HipCenter });
**LayoutRoot.Children.Add**(CreateFigure(skeleton, userBrush, joints));
//Draws the skeleton’s left leg
joints = new [] { JointType.HipLeft, JointType.KneeLeft,
JointType.AnkleLeft, JointType.FootLeft };
**LayoutRoot.Children.Add**(CreateFigure(skeleton, userBrush, joints));
//Draws the skeleton’s right leg
joints = new [] { JointType.HipRight, JointType.KneeRight,
JointType.AnkleRight, JointType.FootRight };
LayoutRoot.Children.Add(CreateFigure(skeleton, userBrush, joints));
//Draws the skeleton’s left arm
joints = new [] { JointType.ShoulderLeft, JointType.ElbowLeft,
JointType.WristLeft, JointType.HandLeft };
LayoutRoot.Children.Add(CreateFigure(skeleton, userBrush, joints));
//Draws the skeleton’s right arm
joints = new [] { JointType.ShoulderRight, JointType.ElbowRight,
JointType.WristRight, JointType.HandRight };
LayoutRoot.Children.Add(CreateFigure(skeleton, userBrush, joints));

      

+3


source to share


1 answer


you can create dashboard like in xaml or in code itself

Xaml example

<Window x:Class="CSharpWPF.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow"
        WindowStartupLocation="CenterScreen">
    <Canvas x:Name="LayoutRoot" >
    </Canvas>
</Windows>

      



or in code like

Canvas LayoutRoot = new Canvas();
using(SkeletonFrame frame = e.OpenSkeletonFrame())
{
    ...
}
//add LayoutRoot to the parent control etc.

      

I used Canvas as a panel with the assumption that you add some numbers to it. You can choose the appropriate control as you like.

+3


source







All Articles