2008年10月26日

唉,SilverLight啊

搞了一段时间的WPF,深深的被那东西吸引了,用WPF开发个东西实在是忒happy了,尽管刚开始的时候忍不了WPF私吞Exception,忍不了傻不啦叽的FrameworkElement.Triggers就支持一个EventTrigger,而傻鸟的EventTrigger偏偏没有个Setter,所以想在某个特定的Event发生的时候对某个属性赋值还得去绕个大圈等等等等。

 据说,SilverLight号称WPF anyware,最近2.0release了,感觉可以花点时间研究一把,结果首先发现WPF中最强大的Binding到了SL里面,没了OneWayToSource,没了ElementName,最猥琐的是,在伊的Path语法当中明明支持hierarchical Binding,结果丫没有ICollectionView接口,做个在WPF中完全用xaml就能搞定的M-D还得借助代码。哦,DataProvider也没了……

 找到一篇抱怨文(原文:https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=333779&wa=wsignin1.0),贴在这了。

 ==============

I’m a big fan of Silverlight and coming from a .Net and WPF background, I was really looking forward to what Silverlight 2.0 had to offer. Sadly, I have ended up highly disappointed as I was hoping to port several high-profile financial industry applications to a more portable framework, but at the moment there are just too many obstacles :o(. It really seems the elegance and separation of concerns of WPF has been replaced by a framework that encourages ‘hard coding’, bad design and minimal reuse. It is somewhat reminiscent of old VB apps with business logic behind buttons! Don’t get me wrong, Silverlight as a Web technology does have enormous potential, but to tout it as being similar to ‘WPF’ is simply not true. I understand the need to streamline WPF, but Silverlight has done more than that, it has removed some of the fundamental principles that made WPF such a good technology. All of the demo applications published by Microsoft showing how easy it is to port between Silverlight /WPF are simply convenient ‘hello world’ type scenarios, and I believe all the marketing and hype around Silverlight and WPF similarities is sending out the wrong message. A WPF app done the WPF way cannot be easily ported to Silverlight, even down to the form definitions. The same is true of the reverse.

Below are some observations I made whilst in my first few hours of Silverlight whilst trying to accomplish several ‘basic’ tasks I would easily accomplish in WPF. I have separated the issues into two categories based on how they have affected my projects. I am hoping at least some of the issues below are resolved in Beta 2 or RTM, or failing that, make it into future Silverlight versions. Let’s keep our fingers crossed :o)

If any Microsoft guys could please give us a clue as to what to expect and when in the Silverlight roadmap then that would be great.



Absolute Show Stoppers
1. Where has MarkupExtension gone? How do we write our own? Are Silverlight bindings from markup “{Binding Forename, ...}” just ‘magic’?


2. How to handle databinding currency, especially with lists as there are no ICollectionView types? E.g. List<People> bound to a textbox, how do we know which person the textbox is displaying?

3. Binding is inconsistent between WPF and Silverlight

No ElementName source
No RelativeSource Self
BindingExpressions not compatible between Silverlight/WPF. Therefore form layout reuse is not possible.

4.No way to get Binding from a control. In WPF we were able to use techniques involving Bindings to know what control was bound to an object and vice versa.

5. No ErrorProvider. In WinForms and ASP.Net there is an out-of-the-box error provider. In WPF it is fairly easy to create an ErrorProvider by tracking the bindings and using AttachedProperties and style triggers with adorners. In Silverlight it seems an awkwardly difficult task! :o(

6. No Adorners. As mentioned above, ErrorProviders in WPF can be implemented with adorners and attached properties. Of course there are a multitude of other reasons as for why Adorners are useful.

7. No ControlTemplate Triggers, DataTemplate triggers, Style Triggers, DataTriggers.


Annoyances

1. No commands/input bindings/gestures – there goes the nicely layered architecture...

2. No ReadOnly DependencyProperties – not a major problem but it is a loss of encapsulation.

3. No tunnelled (preview) events.

4. No RoutedEvent class.

5. No UpdateSourceTrigger=PropertyChanged.

6. Visual / FrameworkContent element missing. Not a major problem, but certainly leads to interesting API changes.

7. No ability to specify a keyless style and have it applied to all matching TargetType..

8. Cannot specify FrameworkMetaData when creating dependency properties. So how to define inheritance behaviour, and default values etc?...

9. No style inheritance -> I.e it is not possible to do ‘BasedOn’...

10. No ValidationRule/ValidationResult.

11. No Xml DataBinding Support.

12. No DynamicResource.

13. No MultiTriggers. 

======================

Community Discussion
 
I agree with this "mismatch" problem, too. Silverlight also removes the Visual class and therefore the separation of concerns between the Logical Tree and Visual Tree. The Silverlight Team's explanation was that this "simplifies" the programming model, even though no defense is given as to why it needed to be simplified and absolutely no debate as to whether developers wanted it simplified. The problem statement above actually says it is "not a major problem", but I disagree.

It seems like Silverlight removes a lot of the infrastructure WPF's architects worked so hard to put in place. Moreover, those of us developing WPF applications are using that infrastructure.

All-in-all, these API differences just seem like a bad move going forward. Once Flex gets multi-platform OS support and Flex desktop applications become more common, there will be a lot less interest in Silverlight AND WPF.
 Posted by jzabroski on 7/16/2008 at 6:21 PM
Agreed. The view that Silverlight is just like WPF but on the web is incorrect, at least with Beta 2. I had expected to be able to use the same source code (IL code?) for controls and UI in WPF and in Silverlight, but I can see this isn't remotely possible.

Due to limitations/missing features in Silverlight I have to implement my functionality in a different way in Silverlight to WPF to "other RIA" technology. In a way my knowledge of WPF isn't helping me with Silverlight.

Bizzarely there are classes in the API that serve no purpose and are there "primarily because of WPF compatibility" (RoutedEvent documentation). This seems nonesense to me.
 Posted by rich257 on 7/17/2008 at 9:15 AM
Actually, the classes in Silverlight that are exist for compatibility with WPF are a good idea. It means Silverlight can eventually grow to become a subset of WPF. My concern is actually in the fact that the Object-Oriented Analysis used by the WPF Architects is being deconstructed by the Silverlight team. They're throwing away parts of the object analysis model by removing classes like Visual. This also complicates porting.

Still, it is clear from your comments that you agree that there is a mismatch and that it makes things confusing, and that knowledge used to build WPF apps has to be thrown away in order to build Silverlight apps.

 

 

posted @ 2008-10-26 22:28 Nineteen@newsmth 阅读(521) 评论(0) 编辑

2007年8月23日

写有效率的SQL查询(VI)

摘要: 这次我们稍微深入的关注Join算法中的NestedLoop和MergeJoin,通过比较它们来看看什么时候指定Join算法可能会得到稍好的性能。
比较的过程中会大量分析图形化的执行计划,所以会顺便讲解如何从执行计划中获取信息、分析信息。

这次分析的一个附属结论(俺小心的提出它来):SQLServer2k5分析执行计划某些情况下和实际的执行操作不同,这会带来比较大的执行计划评估误差。
阅读全文

posted @ 2007-08-23 18:10 Nineteen@newsmth 阅读(67219) 评论(17) 编辑

2007年8月20日

写有效率的SQL查询(V)

摘要: 本文主要讨论在应用程序中使用执行DB指令的三种方式:直接拼SQL、参数化SQL、调用存储过程。并稍微提提参数化SQL的一些小技巧。阅读全文

posted @ 2007-08-20 18:10 Nineteen@newsmth 阅读(73050) 评论(51) 编辑

2007年8月17日

写有效率的SQL查询(IV)

摘要: 本文主要介绍写SQL的另外两个误区:
1、 存储过程中使用局部变量而不使用参数变量(就是存储过程输入参数)做where条件
2、 查询条件中类型不匹配
这两种错误都是非常非常容易犯且非常“发指”的错误,特别是2,已经见过无数次了。
阅读全文

posted @ 2007-08-17 15:39 Nineteen@newsmth 阅读(67688) 评论(12) 编辑

2007年8月8日

写有效率的SQL查询(III)

摘要: 本文主要关注如何写出有效率T-SQL。(SQL2005)

这次主要先粗略说说几个关于索引的 “误区”,然后提提所谓的“涵盖索引”(MSDN上这么翻译,百敬同学的书中叫做覆盖索引)和incluede索引,接着提提SQL2k5中用来分析索引使用情况的动态视图。附带介绍如何通过SQL2k5中的动态视图查看系统中所有SQL语句的运行次数、逻辑IO、物理IO、执行消耗CPU时间等等信息。
阅读全文

posted @ 2007-08-08 22:47 Nineteen@newsmth 阅读(70869) 评论(33) 编辑

2007年8月6日

TransactionScope和分布式事务

摘要: 本文将介绍TransactionScope下使用SqlClient时的bug和fix们,接着介绍介绍怎么做才能稍好一些控制做分布式事务。
顺带着,稍微介绍介绍MSDTC的配置,和测试MSDTC是否联通的初级工具:DTCPing。
阅读全文

posted @ 2007-08-06 13:44 Nineteen@newsmth 阅读(47583) 评论(24) 编辑

2007年8月4日

写有效率的SQL查询(II)

摘要: 本文主要关注如何写出有效率T-SQL。(SQL2005)
该部分将介绍统计信息值分布不均匀对查询的影响和如何避免这些影响,并更多的说说返回多行结果时,为啥SQLServer有时会选择index seek,而有时会选择index scan。
阅读全文

posted @ 2007-08-04 00:21 Nineteen@newsmth 阅读(7185) 评论(25) 编辑

2007年8月3日

写有效率的SQL查询(I)

摘要: 本文主要关注如何写出有效率T-SQL,捎带脚,说说索引。(SQL2005)
BTW:推荐百敬同学那本《SQL性能调校》
阅读全文

posted @ 2007-08-03 16:23 Nineteen@newsmth 阅读(11837) 评论(24) 编辑

2007年7月31日

几种“单例”模式之间的区别

摘要: “单例”的概念是说,数据,在指定的范围内,只有一份。这个所谓的“指定的范围”可能是每进程、每AppDomain、每线程,也可能是每调用。为了在指定的范围内“单例”,可能要采用不同的技术。比方说一个普通的静态属性Instance可以提供很happy的每AppDomain范围;一个ThreadStaticAttribute修饰的s...阅读全文

posted @ 2007-07-31 13:35 Nineteen@newsmth 阅读(1087) 评论(0) 编辑

2007年7月20日

更轻量级的Semaphore、AutoResetEvent、ThreadPool

摘要: 内部完全使用Monitor实现,理论上比使用WaitHandler的资源消耗更少,也更快。缺点是会损失一些功能。Semaphore源码(btw:gotdotnet上面有一个ManagedThreadPool):1usingSystem;2usingSystem.Threading;34namespacenewsmth.Nineteen5{6publicclassSemaphoreLite7{8pr...阅读全文

posted @ 2007-07-20 10:06 Nineteen@newsmth 阅读(2696) 评论(17) 编辑

导航

<2012年2月>
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910

公告

欢迎转载。转载时务必保留本站原始URL和作者信息。
昵称:Nineteen@newsmth
园龄:7年7个月
粉丝:11
关注:0

搜索

 
 

常用链接

随笔档案

积分与排名

  • 积分 - 355298
  • 排名 - 190

最新评论

阅读排行榜

评论排行榜

推荐排行榜