本篇将为大家介绍如何使用scatterview 控件实现上述功能。由于触屏技术只在windows 7 操作系统中支持,所以xp 的用户必须要升级到windows 7 系统。首先,需要在windows 7 中安装surface 2.0 sdk 和runtime,可到官方页面下载安装程序。安装完成后打开vs2010
本篇将为大家介绍如何使用scatterview 控件实现上述功能。由于触屏技术只在windows 7 操作系统中支持,所以xp 的用户必须要升级到windows 7 系统。首先,需要在windows 7 中安装surface 2.0 sdk 和runtime,可到官方页面下载安装程序。安装完成后打开vs2010 新建一个surface 2.0 项目。在模板中选择surface appliction(wpf)。
我们可以在当前的xaml 代码中添加一个label 控件。f5 运行后label 控件是无法进行manipulating 操作的。
s:surfacewindow x:class=scatterview.surfacewindow1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:s=http://schemas.microsoft.com/surface/2008 title=scatterview> grid> label content=surface 2.0 foreground=fuchsia fontweight=bold/> grid>s:surfacewindow>
接下来在grid 中添加一个scatterview 控件。我们可以将scatterview 认为是一个容器能够包含其他控件,并且这些控件均可以实现manipulating 效果。例如,我们在scatterview 中加入rectangle、label、surfacetextbox 三个控件。有些朋友可能会问rectangle 为什么要放在scatterviewitem 里?其实,所有在scatterview 里的控件默认都会自动加入到scatterviewitem,所以如果不需要特别设置可以将scatterviewitem 控件省略。本例中我为了调整rectangle 的减速数值就需要手动写出scatterviewitem 控件,并调整deceleration 参数。
grid> s:scatterview x:name=mainscatterview> s:scatterviewitem deceleration=50> rectangle fill=green width=200 height=100/> s:scatterviewitem> label content=surface 2.0 foreground=fuchsia fontweight=bold/> s:surfacetextbox width=500 height=20 fontsize=20/> s:scatterview>grid>
完成上面代码后,f5 再运行一次。感觉如何?manipulating 效果是不是变得很简单了... ...
如果有需要可以自动加载控件到scatterview,下面代码将自动加入一张本机图片到程序中。
private void adddemopic(){ string targetpic = @c:\users\public\pictures\sample pictures\koala.jpg; scatterviewitem item = new scatterviewitem(); mainscatterview.items.add(item); mediaelement pic = new mediaelement(); item.content = pic; item.background = brushes.transparent; if (system.io.file.exists(targetpic)) { pic.source = new uri(targetpic); } else { item.content = picture not found; }}
至此,本篇关于scatterview 的介绍就到这里,欢迎大家相互交流。
相关参考scatterview class
作者:李敬然(gnie)
出处:{gnietech} (http://www.cnblogs.com/gnielee/)