silverlight教程(8)——创造一个digg桌面应用程序使用wpf

来源:百度文库 编辑:神马文学网 时间:2024/04/28 12:48:27
我们的目标是与这最后的补习是一个有点不同,比以前的7个技术指南,我们其实是一个不会被轻易运行代码silverlight这个教程-相反,我们将使用w pf和。 N ET3 .5,我们都会考虑现行digg应用程序代码,我们写运行里面silverlight在浏览器中,再使用它来运行,也作为Windows桌面应用程序。

Silverlight ships with a compatible API subset of what is in the full version of the .NET Framework.  One goal with this is to enable developers to learn a common programming model and tool-set and be able to re-use skills, code and content across RIA web applications, rich Windows desktop applications, and Office solutions. silverlight船舶与兼容的API子集的是什么,在完整版的。 NET框架,其中一个目标,这是为了让开发人员学习一种通用的编程模型和工具集,并能重复使用的技能,代码和内容跨越规管影响评估的Web应用,丰富的Windows桌面应用程序和办公解决方案。

Below are the steps I took to re-use our existing Digg Silverlight application code (which runs in the browser) to build a Windows desktop application version (which runs outside the browser).下面是步骤,我再充分运用现有digg silverlight应用程序代码(运行在浏览器中) ,以建立一个Windows桌面应用版本(运行以外浏览器) 。

Step 1: Create a New WPF Desktop Application 第1步:创建一个新wpf桌面应用

We'll start by creating a new WPF Desktop Application using VS 2008.  We'll name it "DiggDesktopSample":我们也将开始建立一个新的wpf桌面应用程序与2008年,我们将它的名字" diggdesktopsample " :

This will create a project inside VS with two files - an App.xaml, and a Window.xaml:这将会开创一个项目里面对与这两个文件-一个a pp.xaml,并w indow.xaml:

Note that this project structure is very similar to the Silverlight one we created in Tutorial 1 of this series (which had an App.xaml and a Page.xaml file).注意,这个项目的结构非常相似,该silverlight之一,我们创造补习一本系列(其中有一个app.xaml和page.xaml档案) 。

Step 2) Copy Existing Digg Application Code into the WPF Application 第2步)复制现有digg应用程序代码到wpf应用

We'll copy/paste our existing DiggApplication Silverlight code into our new DiggDesktopSample Windows project:我们将复制/粘贴我们现有diggapplication silverlight码成我们新的diggdesktopsample窗口项目:

Currently in Beta1 this copy/paste effort is a manual step - we will eventually have a more automated way to move the code between project types.目前在素beta1这种复制/粘贴的努力是一种手动的一步-我们最终将有一个更自动化的方法,提出代码之间的项目类型。

Step 3) Fix Up a Few Issues 第3步)修复了几个问题:

I had to make two changes to get our existing Digg sample code to compile:我不得不做出两项重大的转变,以获得我们现有digg样本来编译:

1) The Silverlight Beta1 XAML schema xmlns: URL is different than the full WPF desktop version.  I needed to tweak the XAML files I copied into the new project to point to the full WPF schema.  This is something we are looking to improve before we ship. 1 ) silverlight素beta1 xaml模式xmlns :网址是不同的,较全面wpf桌面版,我需要调节xaml档案复制到新的项目,以点,以充分wpf模式,这是我们正在研究,以改善之前,我们船。

2) I had to change the control to and change the control to be a .  These are two controls that are new in Silverlight Beta1 that aren't in the full WPF yet (we will add them in the future though).  I did not have to change any of the code that worked with these controls, though, nor my network, LINQ to XML, nor databinding code. 2 ) ,我不得不改变控制改变控制是一个 ,这两点是控制新在silverlight素beta1是不是在充分wpf但(我们将其添加在今后虽然) ,我没有改变任何代码的工作,与这些管制措施,虽然,也没有我的网络, linq到XML ,也不和数据绑定代码。

Once I made these small tweaks the project compiled clean.有一次我发了言,这些小的调整项目汇编干净。

Step 4) Hosting the Digg Application in a Desktop Window 第4步)主办digg应用在桌面窗口

I then opened up the Windows1.xaml file in the desktop project (which is the default Window that loads when the application starts).于是我打开了windows1.xaml文件在桌面项目(这是默认的窗口负荷时,接受申请) 。

I updated the Window title to be "Digg Desktop Version" and expanded the default Width and Height of the Window. i更新的窗口标题,以" digg桌面版" ,并扩大了默认的宽度及高度的窗口。

I then added our Page.xaml user control from our previous Digg Silverlight project as the root control in the Window.  This will cause it to be visible and loaded when the Window loads.  I did not have to change the Page class code or rename anything in it.  Because it derives from UserControl it can be hosted just fine inside any WPF Window or Control.我当时补充说:我们page.xaml用户控制,从我们以前digg silverlight工程为从根本上控制在窗口中,这将导致它被可见光和装货时,窗口负荷,我没有要改变一页级代码或重新命名什么在它,因为它来自于usercontrol ,可以主持就万事大吉内任何wpf窗口或控制。

The one last thing I tweaked was an issue caused because the Digg REST API server tries to detect when a non-browser/server accesses it and sometimes gives an access denied response in these cases (probably to avoid allowing automatic scripts from hitting their service).  I fixed this by going through a proxy URL (no code changes, just a URL change).一个我最后随之调整,是一个问题造成的,因为digg休息的API服务器试图探测时non-browser/server通道,它有时还给出了一个拒绝访问回应,在这些情况下, (可能是为了避免让自动脚本由击中服务)我不动,这是由经历一个代理的URL (没有更改代码,只是一个网址不变) 。

Step 5) Running the Application 第5步)运行的应用

I was then able to run our new Digg Desktop Application.当时我能运行我们的新digg桌面应用程序。 All functionality worked the same as the Silverlight version and the application behaved the same:所有功能性工作,同时作为silverlight版本和应用的表现是一样的:

And when a story is selected from the list, the details user control is displayed:当一个故事是挑选出来的名单,详细情况用户控制显示方式:

There are a few cosmetic styling differences between the browser and desktop version.  This is primarily because WPF by default inherits default styles (fonts, colors, scroll bars, etc) based on the operating system theme a user currently has selected, whereas Silverlight has a default theme that we use for all operating systems.  If we wanted to make the desktop version and the browser version absolutely identical we could do so by being more explicit with our Styles and Control Templates - otherwise the desktop version will adapt slightly based on the user's OS theme.有几个美容造型之间的分歧浏览器和桌面版,这主要是因为wpf默认继承了默认的风格(字体,颜色,滚动条等)的基础上,作业系统为主题的用户,目前已经选定,而silverlight有默认主题,我们所用的所有作业系统,如果我们希望使桌面版本和浏览器版本完全一致,我们可以这样做,通过更明确的,与我们的风格和控制模板-否则桌面版将适应稍基于用户的OS的主题。

silverlight教程(8)——创造一个digg桌面应用程序使用wpf silverlight教程(3)---使用Networking取回Digg故事 silverlight教程(7)——使用控制模板来定制一个控制的外观和感觉 silverlight教程(6)——使用用户管制,以落实主/详细情况 silverlight教程(4)---使用风格元素,以更好地概括外观与感觉 微软虚拟桌面(MSVDM)使用教程 silverlight教程(2)--布局管理器 C#面向对象(十):方法的隐藏_ASP.NET学习网_ASP.NET教程|ASP.NET MVC|LINQ|VS2010|jQuery|WPF|Silverlight 一步一步学Silverlight 2系列(1):创建一个基本的Silverlight应用 一步一步学Silverlight 2系列(10):使用用户控件 有道桌面词典3.0使用教程 创建第一个简单的Silverlight应用程序 - Silverlight上海开发团队Bl... 捉WPF应用程序中XAML代码解析异常 使用布局管理 (木野狐译) | Silverlight中文社区 软件测试工具——使用IBM Rational PurifyPlus测试J2EE应用程序:希赛网软件工程频道 使用应用程序资源 Windows Presentation Foundation(WPF)中的数据绑定(使用XmlDataProvider作控件绑定) WPF关于WindowInteropHelper的一个BUG [转贴]完全使用Linux作为桌面系统 —— 使用Linux两年记 [转贴]完全使用Linux作为桌面系统 —— 使用Linux两年记 闲话WPF之二五(WPF中的ControlTemplate [3]) 闲话WPF之十七(WPF中的资源 [3]) 闲话WPF之二二(WPF中的Style) 闲话WPF之十八(WPF中的资源 [4] )