c#-名称LayoutRoot在当前上下文中不存在
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c#-名称LayoutRoot在当前上下文中不存在,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2345字,纯文字阅读大概需要4分钟。
内容图文
![c#-名称LayoutRoot在当前上下文中不存在](/upload/InfoBanner/zyjiaocheng/661/997968886fbc48cfae92ff44f3630eb5.jpg)
我收到以下erorr代码:“名称LayoutRoot在当前上下文中不存在”.
我还没有在Xaml文件中编写任何控件,因为在toolBox中找不到控件“ LayoutRoot”.我怎么解决这个问题?
这是我的代码:
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));
解决方法:
您可以在xaml或代码本身中创建一些类似于控件的面板
xaml示例
<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>
或类似的代码
Canvas LayoutRoot = new Canvas();
using(SkeletonFrame frame = e.OpenSkeletonFrame())
{
...
}
//add LayoutRoot to the parent control etc.
我使用Canvas作为面板,并假设您要向其中添加一些数字.您可以根据需要选择适当的控件.
内容总结
以上是互联网集市为您收集整理的c#-名称LayoutRoot在当前上下文中不存在全部内容,希望文章能够帮你解决c#-名称LayoutRoot在当前上下文中不存在所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。
来源:【匿名】