Windows 8.1 应用再出发 (WinJS) - 几种新增控件(1)

简介: 原文:Windows 8.1 应用再出发 (WinJS) - 几种新增控件(1)Windows 8.1 和 WinJS 引入了以下新控件和功能,分别是:AppBarCommand、BackButton、Hub、ItemContainer、NavBar、Repeater、WebView。
原文: Windows 8.1 应用再出发 (WinJS) - 几种新增控件(1)


Windows 8.1 和 WinJS 引入了以下新控件和功能,分别是:AppBarCommand、BackButton、Hub、ItemContainer、NavBar、Repeater、WebView。

本篇我们先来介绍 AppBarCommand、BackButton、Hub、ItemContainer,其余三种放在下一篇中介绍。

1. AppBarCommand

Windows 8.1 加入了AppBarCommand 控件来创建自定义应用栏命令。AppBarCommand可以是这几种类型:button、toggle、flyout、separator 和 content。我们来看一个例子:

<body>
    <div id="exampleFlyout" data-win-control="WinJS.UI.Flyout" aria-label="{Example flyout}">
        <div>This is an example AppBarCommand of type 'flyout'.</div>
    </div>
    <div id="appBar" data-win-control="WinJS.UI.AppBar" data-win-options="{placement:'bottom'}">
        <div data-win-control="WinJS.UI.AppBarCommand"
             data-win-options="{ id: 'list', type: 'content', label:'List', section: 'selection'}">
            <select class="options">
                <option>Option1</option>
                <option>Option2</option>
                <option>Option3</option>
                <option>Option4</option>
            </select>
        </div>
        <div data-win-control="WinJS.UI.AppBarCommand"
             data-win-options="{ id: 'textfield', type: 'content', label:'Text field', section: 'selection' }">
            <input type="text" value="Text" />
        </div>
        <button data-win-control="WinJS.UI.AppBarCommand"
                data-win-options="{id:'flyoutButton', type:'flyout', label:'Flyout', icon:'document', section: 'selection', 
                flyout:select('#exampleFlyout')}"/>
        <button data-win-control="WinJS.UI.AppBarCommand"
                data-win-options="{id:'cmdToggle', type:'toggle', label:'Toggle', icon:'video', section:'global', tooltip:'Toggle'}"/>
        <hr data-win-control="WinJS.UI.AppBarCommand"
            data-win-options="{id:'separator', type:'separator', section:'global'}" />
        <button data-win-control="WinJS.UI.AppBarCommand"
                data-win-options="{id:'helpButton', type: 'button', label:'Help', tooltip:'Help', icon:'help', section:'global'}"/>
    </div>
</body>

在这个例子中,我们演示了在页面底部的AppBar中 button、toggle 等五种类型的AppBarCommand。AppBar 中的 AppBarCommand 之间支持键盘操作,比如Tab, Enter, 箭头,Home 和 End 键。

另外应用缩小到半屏宽后,文本标签不会再显示。这个XAML中的特性是相似的。

 

2. BackButton

顾名思义,BackButton 可以简单的在应用中添加后退导航功能,BackButton 会自动检查导航堆栈,来决定是否让用户后退。如果没有后退导航的内容,按钮会自动禁用。按钮会自动调用WinJS.Navigation.back函数来完成导航动作,无需另写代码。来看看代码写法:

    <button data-win-control="WinJS.UI.BackButton" ></button>

   

 

3. Hub

Windows 8.1 在XAML 和WinJS 中加入了Hub,也就是中心控件。它可以帮我们更轻松的创建中心页,例如应用商店的首页就是一个中心页。Hub控件可以包含多个HubSection对象,每个HubSection可以包含内容和标题。标题可以选择是否隐藏 > 图标,显示时,标题可以交互。来看看例子:

    <div class="hub" data-win-control="WinJS.UI.Hub">
        <div class="section1" data-win-control="WinJS.UI.HubSection" data-win-options="{ isHeaderStatic: true }" data-win-res="{ winControl: {'header': 'Section1'} }">
            <img src="/images/gray.png" width="420" height="280" />
            <div class="subtext win-type-x-large" data-win-res="{ textContent: 'Section1Subtext' }"></div>
            <div class="win-type-medium" data-win-res="{ textContent: 'DescriptionText' }"></div>
            <div class="win-type-small">
                <span data-win-res="{ textContent: 'Section1Description' }"></span>
                <span data-win-res="{ textContent: 'Section1Description' }"></span>
                <span data-win-res="{ textContent: 'Section1Description' }"></span>
            </div>
        </div>

        <div class="section2" data-win-control="WinJS.UI.HubSection" data-win-res="{ winControl: {'header': 'Section2'} }">
            <div class="item-title win-type-medium" data-win-res="{ textContent: 'Section2ItemTitle',  }"></div>
            <div class="article-header win-type-x-large" data-win-res="{ textContent: 'Section2Subtext' }"></div>
            <div class="win-type-xx-small" data-win-res="{ textContent: 'Section2ItemSubTitle' }"></div>
            <div class="win-type-small">
                <span data-win-res="{ textContent: 'Section2Description' }"></span>
                <span data-win-res="{ textContent: 'Section2Description' }"></span>
                <span data-win-res="{ textContent: 'Section2Description' }"></span>
                <span data-win-res="{ textContent: 'Section2Description' }"></span>
                <span data-win-res="{ textContent: 'Section2Description' }"></span>
                <span data-win-res="{ textContent: 'Section2Description' }"></span>
            </div>
        </div>
    </div>

 

4. ItemContainer

ItemContainer 可以为元素提供pressed,swiped 和 dragged 功能,把我们需要的元素加入到ItemContainer 中即可。例如我们需要显示元素,又不需要用到ListView 中全部功能时,就可以选择ItemContainer控件。其中tapBehavior 属性设置为toggleSelect 时,对象可以被选择。设置为none,并且selectionDisabled 设置为 true 时,元素不能被选择。我们来看一个简单的例子:

<div style="margin: 150px 10px 20px 150px; width: 200px;" id="item1"
            data-win-control="WinJS.UI.ItemContainer"
            data-win-options="{tapBehavior: 'toggleSelect'}">
        <div style="margin: 10px; padding: 10px; background-color: gray">
            <div class="win-type-x-large"
                    style="margin-bottom: 5px;">
                晴天
            </div>
            <img src="/images/d00.gif">
            <div>晴天</div>
        </div>
    </div>
    <div style="margin: 250px 10px 150px 150px; width: 200px;" id="item2"
            data-win-control="WinJS.UI.ItemContainer"
            data-win-options="{tapBehavior: 'none', selectionDisabled: 'true'}">
        <div style="margin: 10px; padding: 10px; background-color: gray;">
            <div class="win-type-x-large"
                    style="margin-bottom: 5px;">
                多云
            </div>
            <img src="/images/d01.gif">
            <div>多云</div>
        </div>
    </div>

这里我们并没有对css做调整,主要为了演示第一个元素是可以被选择的,而第二个元素则没有选中状态。

 

到这里我们就把 AppBarCommand、BackButton、Hub、ItemContainer 四种控件介绍完了,下一篇会介绍剩余三种控件,谢谢。

目录
相关文章
|
1天前
|
数据可视化 程序员 C#
C#中windows应用窗体程序的输入输出方法实例
C#中windows应用窗体程序的输入输出方法实例
5 0
|
2月前
|
Unix Linux Ruby
在windows和linux上高效快捷地发布Dash应用
在windows和linux上高效快捷地发布Dash应用
|
2月前
|
Linux iOS开发 开发者
跨平台开发不再难:.NET Core如何让你的应用在Windows、Linux、macOS上自如游走?
【8月更文挑战第28天】本文提供了一份详尽的.NET跨平台开发指南,涵盖.NET Core简介、环境配置、项目结构、代码编写、依赖管理、构建与测试、部署及容器化等多个方面,帮助开发者掌握关键技术与最佳实践,充分利用.NET Core实现高效、便捷的跨平台应用开发与部署。
73 3
|
2月前
|
vr&ar C# 图形学
WPF与AR/VR的激情碰撞:解锁Windows Presentation Foundation应用新维度,探索增强现实与虚拟现实技术在现代UI设计中的无限可能与实战应用详解
【8月更文挑战第31天】增强现实(AR)与虚拟现实(VR)技术正迅速改变生活和工作方式,在游戏、教育及工业等领域展现出广泛应用前景。本文探讨如何在Windows Presentation Foundation(WPF)环境中实现AR/VR功能,通过具体示例代码展示整合过程。尽管WPF本身不直接支持AR/VR,但借助第三方库如Unity、Vuforia或OpenVR,可实现沉浸式体验。例如,通过Unity和Vuforia在WPF中创建AR应用,或利用OpenVR在WPF中集成VR功能,从而提升用户体验并拓展应用功能边界。
40 0
|
2月前
|
存储 开发者 C#
WPF与邮件发送:教你如何在Windows Presentation Foundation应用中无缝集成电子邮件功能——从界面设计到代码实现,全面解析邮件发送的每一个细节密武器!
【8月更文挑战第31天】本文探讨了如何在Windows Presentation Foundation(WPF)应用中集成电子邮件发送功能,详细介绍了从创建WPF项目到设计用户界面的全过程,并通过具体示例代码展示了如何使用`System.Net.Mail`命名空间中的`SmtpClient`和`MailMessage`类来实现邮件发送逻辑。文章还强调了安全性和错误处理的重要性,提供了实用的异常捕获代码片段,旨在帮助WPF开发者更好地掌握邮件发送技术,提升应用程序的功能性与用户体验。
42 0
|
2月前
|
C# Windows 监控
WPF应用跨界成长秘籍:深度揭秘如何与Windows服务完美交互,扩展功能无界限!
【8月更文挑战第31天】WPF(Windows Presentation Foundation)是 .NET 框架下的图形界面技术,具有丰富的界面设计和灵活的客户端功能。在某些场景下,WPF 应用需与 Windows 服务交互以实现后台任务处理、系统监控等功能。本文探讨了两者交互的方法,并通过示例代码展示了如何扩展 WPF 应用的功能。首先介绍了 Windows 服务的基础知识,然后阐述了创建 Windows 服务、设计通信接口及 WPF 客户端调用服务的具体步骤。通过合理的交互设计,WPF 应用可获得更强的后台处理能力和系统级操作权限,提升应用的整体性能。
77 0
|
2月前
|
网络安全 API 数据安全/隐私保护
【Azure App Service】.NET代码实验App Service应用中获取TLS/SSL 证书 (App Service Windows)
【Azure App Service】.NET代码实验App Service应用中获取TLS/SSL 证书 (App Service Windows)
|
Windows
Windows 8.1 新增控件之 Hyperlink
原文:Windows 8.1 新增控件之 Hyperlink Hyperlink 控件应该不用过多介绍大家肯定十分清楚其作用,它的功能就像HTML中的标签一样,只不过是在XAML中实现。 使用Hyperlink 标记的文字在应用中会以特殊颜色显示,当用户点击或触碰该文字时就会自动转到NavigateUri 指向的地址链接。
777 0
|
1月前
|
网络安全 虚拟化 Windows
windows 11安装openSSH server 遇到的"kex_exchange_identification: read: Connection reset"问题
windows 11安装openSSH server 遇到的"kex_exchange_identification: read: Connection reset"问题