您的位置:首页 > 其它

WPF and Silverlight 学习笔记(二):WPF和Silverlight概述

2012-06-07 10:28 609 查看
WPF(Windows Presentation Foundation,Windows外观基础(直译))是基于Framework 3.0(含以后版本)的新一代Windows界面开发技术。

Silverlight(中文翻译为“银光”),可以看成是WPF的Web应用产品,其早先名为WPF/E。其主要应用于Web富客户端应用程序(RIA,Rich Interface Application)。现阶段此技术可以说比较“火”,微软在此方面主要的对手就是Adobe公司的以Flash为基础的Flex技术。

两者均是以XAML为基础的,在某些条件下是可以相互的转换:如定义一个简单的ARGB调色版应用:

WPF应用程序如下:

XAML文件:

代码文件

using System.Windows;
using System.Windows.Media;

namespace WPFColorVersion
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}

private void sliderValueChanged(object sender, System.Windows.RoutedPropertyChangedEventArgs<double> e)
{
byte a = (byte)(sliderA.Value);
byte r = (byte)(sliderR.Value);
byte g = (byte)(sliderG.Value);
byte b = (byte)(sliderB.Value);

Color clr = Color.FromArgb(a, r, g, b);

demoArea.Fill = new SolidColorBrush(clr);
txtColorValue.Text = clr.ToString();
}
}
}


而对应在Silverlight中,XAML文件内:

<UserControl x:Class="SilverlightColorVersion.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<!--此位置与WPF项目的XAML文件内容完全相同-->
</UserControl>


另外,Silverlight的代码文件内容也与WPF项目中的代码相同。

WPF应用程序执行的结果如下:





在FireFox(3.0.8)及IE(8.0)中执行Silverlight项目的结果如下:







从此可以看出,WPF与Silverlight有着千丝万缕的联系,我们在学习过程中可以相互的对比。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐