环境搭建好了,下面从一个最简单的应用程序开始练习SilverLight编程。
具体如图:
解决方案浏览器:
Page.xaml代码如下:
<
UserControl
x:Class
="SilverlightApplication1.Page"
xmlns ="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x ="http://schemas.microsoft.com/winfx/2006/xaml"
Width ="400" Height ="300" >
< Grid x:Name ="LayoutRoot" Background ="White" >
< Button x:Name ="myButton" Content ="点我" Width ="200" Height ="50"
Foreground ="Red" Click ="myButton_Click" > </ Button >
</ Grid >
</ UserControl >
xmlns ="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x ="http://schemas.microsoft.com/winfx/2006/xaml"
Width ="400" Height ="300" >
< Grid x:Name ="LayoutRoot" Background ="White" >
< Button x:Name ="myButton" Content ="点我" Width ="200" Height ="50"
Foreground ="Red" Click ="myButton_Click" > </ Button >
</ Grid >
</ UserControl >
<
UserControl>
是SilverLight的根容器
<
Grid >是布局容器,如果有Java Swing编程经验的人,对这个理解会比较快一点。
<
Button >是一个按钮
Page.xaml.cs代码如下:
实现如果点击按钮,则在按钮上显示
"Hello SilverLight!",
并且按钮背景色变为红色。
运行测试和其它应用程序一致,点击运行图表或者菜单项就可以了。
运行效果如下:
OK,从创建项目到创建xaml文件,这是我们接下来不断重复的步骤。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。