wpf ui界面设计WPF UI interface design.docx
- 文档编号:27974755
- 上传时间:2023-07-07
- 格式:DOCX
- 页数:13
- 大小:18.31KB
wpf ui界面设计WPF UI interface design.docx
《wpf ui界面设计WPF UI interface design.docx》由会员分享,可在线阅读,更多相关《wpf ui界面设计WPF UI interface design.docx(13页珍藏版)》请在冰豆网上搜索。
wpfui界面设计WPFUIinterfacedesign
wpfui界面设计(WPFUIinterfacedesign)
wpfui界面设计(WPFUIinterfacedesign)
使用系统;
使用system.collections.generic;
使用LINQ系统;
使用系统窗口;
使用system.windows.automation.peers;
使用system.windows.automation.provider;
使用system.windows.controls;
使用system.windows.controls.primitives;
使用system.windows.media;
使用system.windows.media.imaging;
使用system.windows.shapes;
使用coding4fun.kinect.wpf;
使用coding4fun.kinect.wpf.controls;
使用微软Kinect;
命名空间kinecthubdemo
{
公共部分类主要窗口:
窗口
{
kinectsensorKinect;
私有列表<按钮>按钮;
hoveredbutton专用按钮;
私人布尔iswindowsclosing=假;
<<摘要>
///启动Kinect设备,默认初始化选项,并注册allframesready
同步事件
//
privatevoidstartkinect()
{
如果(kinectsensor.kinectsensors.count>0)
{
//选择第一个Kinect设备
Kinect=kinectsensorkinectsensors[0];
如果(Kinect=NULL)
返回;
Kinect。
COLORSTREAM。
enable();
VaRTSP=新transformsmoothparameters
{
0.5f平滑=,
0.5f校正=,
预测=0.5f,
jitterradius=0.05f,
maxdeviationradius=0.04f
};
Kinect。
skeletonstream使(TSP);
//启用骨骼跟踪,并在屏幕右下方显示彩色视频信息
kinect.colorframeready+=新EventHandler
kinect.skeletonframeready+=新EventHandler<
skeletonframereadyeventargs>(kinect_skeletonframeready);
//启动Kinect设备
start()Kinect;
}
其他的
{
MessageBox显示(“没有发现任何Kinect设备”);
}
}
无效kinect_skeletonframeready(objectsender,skeletonframereadyeventargsE)
{
使用(skeletonframe框架=Eopenskeletonframe())
{
如果(帧=NULL)
返回;
如果(frame.skeletonarraylength==0)
返回;
骨架[]allskeletons=新的骨架skeletonarraylength][帧;
CopySkeletonDataTo(allskeletons)框架;
The//LinqsyntaxsearchesfortheclosesttrackedskeletonfromKinect,usingtheheadZcoordinatesasareference
SkeletonclosestSkeleton=(from,s,in,allSkeletons)
Where=SkeletonTrackingState.Tracked&&s.TrackingState
S.Joints[JointType.Head].TrackingState==
JointTrackingState.Tracked
Selects.OrderBy(s)=>s.Joints[JointType.Head].Position.Z)
.FirstOrDefault();
If(closestSkeleton=null)
Return;
If(closestSkeleton.TrackingState==
SkeletonTrackingState.Tracked)
Return;
Varjoints=closestSkeleton.Joints;
JointrightHand=joints[JointType.HandRight];
JointleftHand=joints[JointType.HandLeft];
TheYaxis//judgmentisrightorleft-handedhabits:
onehandtolifttheYaxisislarger
Varhand=(rightHand.Position.Y>leftHand.Position.Y)
RightHand?
:
leftHand;
If(hand.TrackingState==JointTrackingState.Tracked)
Return;
//getthescreenwidthandheight
IntscreenWidth=(int)SystemParameters.PrimaryScreenWidth;
IntscreenHeight=(int)
SystemParameters.PrimaryScreenHeight;
Thepositionof"skeletoncoordinatemapping/handtoscreencoordinates;handonlyneedtomoveinalimitedrangecancovertheentirescreenarea
Float,posX=hand.ScaleTo(screenWidth,screenHeight,0.2f,0.2f).Position.X;
Float,posY=hand.ScaleTo(screenWidth,screenHeight,0.2f,0.2f).Position.Y;
//judgewhethersuspendedinthepicturebutton,thentriggertheClickevent
OnButtonLocationChanged(kinectButton,buttons,(int)posX,(int)posY);
}
}
Voidkinect_ColorFrameReady(object,sender,
ColorImageFrameReadyEventArgs,e)
{
Using(ColorImageFrame,colorFrame=e.OpenColorImageFrame())
{
If(colorFrame=null)
{
Return;
}
Thelowerrightcornerofthescreendisplay/colorcamera,
usingtheCoding4Fun.Kinect.Wpfextensionmethod
VideoImage.Source=colorFrame.ToBitmapSource();
}
}
Public,MainWindow()
{
InitializeComponent();
KinectButton.
click+=newroutedeventhandler(kinectbutton_clicked);
}
privatevoidinitializebuttons()
{
buttons=newlist
{
button1.
button2.
button3.
button4.
button5.
button6
};
}
///(summary)
///悬停选择按钮处理
///->/summary
///
///
///
///
privatevoidonbuttonlocationchanged(hoverbuttonhand,listbuttons,intx,inty)
{
if(isbuttonoverobject(hand,buttons)
hand.hovering();//触发mouseclick事件
else
hand.release();
//移动手型光标
canvas.setleft(hand,x-(hand.actualwidth/2));
canvas.settop(hand,y-(hand.actualheight/2));
}
privatevoidkinectbutton_clicked(objectsender,routedeventargsand)
{
hoveredbutton.raiseevent(newroutedeventargs(buttonbase.clickevent,hoveredbutton));
}
publicboolisbuttonoverobject(frameworkelementhand,listbuttons)
{
if(iswindowsclosing||!
window.getwindow(hand).isactive)
returnfalse;
//找到悬浮手型控件的中心点位置
varhandtopleft=newpoint(canvas.gettop(hand),canvas.getleft(hand);
doublehandleft=handtopleft.x+(hand.actualwidth/2);
doublehandtop=handtopleft.y+(hand.actualheight/2);
//遍历图片按钮,判断hand图标是否悬浮在其中之一
foreach(buttontargetbuttons)
{
pointtargettopleft=target.pointtoscreen(newpoint());
if(handtop>targettopleft.x
&&handtop &&handleft>targettopleft.y &&handleft { hoveredbutton=target; returntrue; } } returnfalse; } privatevoidpromotebuttonclickevent(stringinfo) { listboxhoverevent.items.add(string.format("{0}: {1}",info,datetime.now.tostring("t"))); } privatevoidbutton1_click(objectsender,routedeventargsand) { promotebuttonclickevent("button1clicked"); } privatevoidbutton2_click(objectsender,routedeventargs and) { promotebuttonclickevent("button2clicked"); } privatevoidbutton3_click(objectsender,routedeventargsE) { promotebuttonclickevent(”按钮3单击“); } privatevoidbutton4_click(objectsender,routedeventargsE) { promotebuttonclickevent(”按钮4单击“); } privatevoidbutton5_click(objectsender,routedeventargsE) { promotebuttonclickevent(”按钮5单击“); } privatevoidbutton6_click(objectsender,routedeventargsE) { promotebuttonclickevent(”按钮6单击“); } privatevoidcanvas_loaded(objectsender,routedeventargsE) { } privatevoidstopkinect() { 如果(Kinect)~=null) { 如果(kinect.status==kinectstatus。 连接) { //关闭Kinect设备 stop()Kinect; } } } privatevoidwindow_loaded(objectsender,routedeventargsE) { initializebuttons(); startkinect(); } privatevoidwindow_closing(objectsender,ponentmodel.canceleventargsE) { iswindowsclosing=真; stopkinect(); } } } //界面: : : : <窗口X: class=“kinecthubdemo。 主窗口” WindowState=“最大化” windowstyle=“singleborderwindow” xmlns =“ n” xmlns: x=“; 背景=“#1e1c37” xmlns: 控制=“CLR命名空间: coding4fun。 Kinect。 WPF。 控制;装配=coding4funWPF。 Kinect。 ” 标题=“Kinect枢纽演示”height=“800”width=“1280”加载 =“window_loaded”关闭=“window_closing”> <网格X: 名称=“网格”> <画布背景=“透明”=“{}DataContext绑定“装=“canvas_loaded”> <操作: hoverbutton缘=“0”=“0”x: 填料名称=“kinectbutton”图像大小=“64” 图像源=“/资源/hand_basic。 png” activeimagesource=“/资源/hand_basic。 png” 时间间隔=“2000”=“525”画布。 离开画布。 =“32”面板,在“1000”/>= 左=“48”=“32”画布,字体大小=“46”=“白色”前景高度=“101”name=“textblock3”文本=“Kinect枢纽演示”width=“448”/> <按钮帆布。 左=“45”帆布。 =“118”height=“200”name=“Button1”width=“338”horizont alcontentalignment=“正确”的verticalcontentalignment=“底 层”单击“=”button1_click”> <按钮>背景> 资源/图片/kinect-hub001。 png”/> <按钮>背景> <按钮> <按钮帆布。 左=“455”=“115”画布。 顶部高度 =“200”name=“button2”width=“335”horizontalcontentalign ment=“正确”的verticalcontentalignment=“底层”单击“=”button2_click”> <按钮>背景> 资源/图片/kinect-hub002。 png”/> <按钮>背景> <按钮> <按钮帆布。 左=“853”=“112”画布。 顶部高度=“200”name=“按钮”width=“322” horizontalcontentalignment=“正确”的verticalcontentalignment=“底层”单击“=”button3_click”> <按钮>背景> 资源/图片/kinect-hub003。 png”/> <按钮>背景> <按钮> <按钮帆布。 左=“45”=“345”画布。 顶部高度=“200”name=“步button4”width=“335” horizontalcontentalignment=“正确”的verticalcontentalignment=“底层”单击“=”button4_click”> <按钮>背景> png”/> <按钮>背景> <按钮> <按钮帆布。 左=“452”=“342”画布。 顶部高度=“200”name=“按钮”width=“338” horizontalcontentalignment=“正确”的verticalcontentalignment=“底层”单击“=”button5_click”> <按钮>背景> png”/> <按钮>背景> <按钮> <按钮帆布。 左=“850”=“348”画布。 顶部高度 =“200”name=“button6”width=“318” horizontalcontentalignment=“正确”的 verticalcontentalignment=“底层”单击“=”button6_click”> <按钮>背景> png”/> <按钮>背景> <按钮> 字体大小=“24” 名称 =“texttip”文本=“提示: 波Kinect光标”width=“289”帆布。 左=“963”=“575顶帆布。 ”/> <图片名称=“电视”height=“140”width=“235”帆布。 左=“1017”=“615”画布。 顶><图像> <列表框的画布。 左=“44”=“615”画布。 顶部高度 =“128”name=“listboxhoverevent”width=“339”背景=“# ff1e1c37”前景=“#ff20ed16”/> <画布> <网格> <窗口>
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- wpf ui界面设计WPF UI interface design 界面设计