Windows 8实用窍门系列:1.使用Xaml+C#开发第一个Metro Style应用程序

简介:

首先我们需要安装Windows 8以及VS2012,下载地址:http://msdn.microsoft.com/zh-CN/windows/apps/br229516/ 

  然后我们打开VS2012,选择Windows Metro Style,然后选择创建Blank App项目如下图:

  

  其新建完成的项目结构如下: 

     

  我们拖动一个按钮和ListBox到界面中,设置按钮事件以及ListBox的DataTemplate,如下Xaml代码:

    <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
        <Button Content="Button" Name="button1" HorizontalAlignment="Left" 
                Margin="135,124,0,0" VerticalAlignment="Top" Click="button1_Click"/>
        <ListBox HorizontalAlignment="Left" Name="listbox1" Height="100"
                 Margin="135,187,0,0" VerticalAlignment="Top" Width="140">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock  Width="60" Text="{Binding ItemName}"/>                    
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>

  其Xaml.cs文件如下:

    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
            listbox1.ItemsSource = ItemModel.GetItem();
            button1.Content = "Windows 8按钮";
        }

        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            this.button1.Content = this.button1.Content + "1";
        }
    }

  ListBox绑定的数据源代码如下:

    public class ItemModel
    {
        public string ItemName { get; set; }

        public string ItemValue { get; set; }

        public static List<ItemModel> GetItem()
        {
            List<ItemModel> list = new List<ItemModel>();
            list.Add(new ItemModel() { ItemName = "北京", ItemValue = "010" });
            list.Add(new ItemModel() { ItemName = "上海", ItemValue = "020" });
            list.Add(new ItemModel() { ItemName = "成都", ItemValue = "028" });
            return list;
        }
    }

  运行效果图如下: 

     



本文转自程兴亮 51CTO博客,原文链接:http://blog.51cto.com/chengxingliang/1009048

相关文章
|
1月前
|
Windows
Windows下版本控制器(SVN)-验证是否安装成功+配置版本库+启动服务器端程序
Windows下版本控制器(SVN)-验证是否安装成功+配置版本库+启动服务器端程序
84 2
|
2月前
|
Windows
Windows下版本控制器(SVN)-启动服务器端程序
Windows下版本控制器(SVN)-启动服务器端程序
94 4
|
3月前
|
安全 Devops 测试技术
AppSpider 7.5.018 for Windows - Web 应用程序安全测试
AppSpider 7.5.018 for Windows - Web 应用程序安全测试
68 0
AppSpider 7.5.018 for Windows - Web 应用程序安全测试
|
4月前
|
SQL 小程序 API
如何运用C#.NET技术快速开发一套掌上医院系统?
本方案基于C#.NET技术快速构建掌上医院系统,结合模块化开发理念与医院信息化需求。核心功能涵盖用户端的预约挂号、在线问诊、报告查询等,以及管理端的排班管理和数据统计。采用.NET Core Web API与uni-app实现前后端分离,支持跨平台小程序开发。数据库选用SQL Server 2012,并通过读写分离与索引优化提升性能。部署方案包括Windows Server与负载均衡设计,确保高可用性。同时针对API差异、数据库老化及高并发等问题制定应对措施,保障系统稳定运行。推荐使用Postman、Redgate等工具辅助开发,提升效率与质量。
152 0
|
5月前
|
Windows
Windows程序的数字签名证书怎么申请
Windows程序的数字签名证书申请流程包括:准备企业资料(营业执照、税务登记证等),提交申请表及企业资料。经过初审、实名认证和二审后,等待1-5个工作日审核结果。审核通过后,CA机构颁发证书并通过邮件或邮寄方式发送。收到证书后按指南安装并使用签名工具对程序进行数字签名,确保软件完整性和可信度。注意证书有效期、管理和兼容性问题。
|
5月前
|
自然语言处理 安全 测试技术
HCL AppScan Standard 10.8.0 (Windows) - Web 应用程序安全测试
HCL AppScan Standard 10.8.0 (Windows) - Web 应用程序安全测试
254 0
HCL AppScan Standard 10.8.0 (Windows) - Web 应用程序安全测试
|
6月前
|
安全 JavaScript Java
AppSpider Pro 7.5.015 for Windows - Web 应用程序安全测试
AppSpider Pro 7.5.015 for Windows - Web 应用程序安全测试
77 12
AppSpider Pro 7.5.015 for Windows - Web 应用程序安全测试
|
C# Windows
C#编写Windows服务
一.Windows服务介绍: 一个Windows服务程序是在Windows操作系统下能完成特定功能的可执行的应用程序。Windows服务程序虽然是可执行的,但是它不像一般的可执行文件通过双击就能开始运行了,它必须有特定的启动方式。
1121 0
|
C# Windows 调度
C#/.NET基于Topshelf创建Windows服务程序及服务的安装和卸载(极速,简洁)
C#/.NET基于Topshelf创建Windows服务程序及服务的安装和卸载(极速,简洁)本文首发于:码友网--一个专注.NET/.NET Core开发的编程爱好者社区。 文章目录C#/.NET基于Topshelf创建Windows服务的系列文章目录: C#/.
1739 0
|
C# Windows
使用C#创建windows服务续之使用Topshelf优化Windows服务
前言: 之前写了一篇“使用C#创建windows服务”,https://www.cnblogs.com/huangwei1992/p/9693167.html,然后有博友给我推荐了一个开源框架Topshelf。
1560 0

热门文章

最新文章