您的位置:首页 > 其它

Silverlight学习笔记1:创建一个Silverlight应用程序

2011-09-21 12:49 459 查看
以VS2010作为开发工具,首先启动Visual Studio,然后点击“文件”-->“新建项目”,在模版中选择silverlight,输入名称点确定后在新弹出窗口中选择silverlight版本,创建一个SilverlightSimple1的项目。

1.新建项目后分为两个部分:

a. asp.net网站项目

新建后包含以下文件:

Silverlight.js :提供一些 JavaScript 帮助器函数,这些函数用于将 Silverlight 插件嵌入某一网页和用于自定义 Silverlight 安装体验。

SilverlightSimple1TestPage.aspx和 SilverlightSimple1TestPage.html一样都是用来承载silverlight应用程序的测试页。

Web.config asp.net网站项目的配置文件

b.应用程序项目

应用程序中会产生两个xaml文件,分别是App.xaml和MainPage.xaml以及相应的App.xaml.cs和MainPage.xaml.cs

3.创建应用程序

(1).修改xaml中页面宽度和高度分别为300和400像素,并在<Grid>..</Grid>中加入TextBlock元素,设置其字体,代码如下:

<UserControl x:Class="SilverlightSimple1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">

<Grid x:Name="LayoutRoot" Background="White">
<TextBlock Text="文本显示" FontFamily="宋体" Foreground="Blue" FontSize="12"></TextBlock>
</Grid>
</UserControl>


(2).修改填充色(实现简单的填充效果)

<UserControl x:Class="SilverlightSimple1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">

<Grid x:Name="LayoutRoot" Background="White">
<TextBlock Text="文本显示" FontFamily="宋体" FontSize="12">
<!-- 使用渐变画刷填充文本产生渐变效果-->
<TextBlock.Foreground>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black"></GradientStop>
<GradientStop Color="White" Offset="1"></GradientStop>
</LinearGradientBrush>
</TextBlock.Foreground>
</TextBlock>
</Grid>
</UserControl>


LinearGradientBrush :线性渐变填充属性元素。

GradientStop:控制渐变颜色由黑到白,

EndPoint ,StartPoint:控制渐变角度

Offset:控制渐变范围

最终效果如下:



Silverlight项目也可在浏览器外进行访问,进行设置只需选中工程,右键属性,将“允许浏览器外运行程序”选项勾选即可脱离浏览器进行访问。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐