登录  /  注册

WPF 与Surface 2.0 SDK 亲密接触

php中文网
发布: 2016-06-07 15:20:13
原创
915人浏览过

本篇将为大家介绍如何使用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)。

WPF 与Surface 2.0 SDK 亲密接触

     我们可以在当前的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>
登录后复制
WPF 与Surface 2.0 SDK 亲密接触

     接下来在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 效果是不是变得很简单了... ...

WPF 与Surface 2.0 SDK 亲密接触

如果有需要可以自动加载控件到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";
    }
}
登录后复制

WPF 与Surface 2.0 SDK 亲密接触

至此,本篇关于ScatterView 的介绍就到这里,欢迎大家相互交流。

相关参考

ScatterView Class

作者:李敬然(Gnie)
出处:{GnieTech} (http://www.cnblogs.com/gnielee/)

相关标签:
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 技术文章
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2023 //m.sbmmt.com/ All Rights Reserved | 苏州跃动光标网络科技有限公司 | 苏ICP备2020058653号-1

 | 本站CDN由 数掘科技 提供

登录PHP中文网,和优秀的人一起学习!
全站2000+教程免费学