CommandBinding

这篇问题的解答说到了一个很容易被忽略的地方:

A CommandBinding is just like any other element in your visual tree. Any events specified on it will be handled by the root of your visual tree (your Window in this case).

所以必须在Code Behind里写点什么,才能让一个按钮的亮起与灰掉被判断。

Update:或者用实现了ICommand的东西来绑定到Command Property上(Button,MenuItem等都有),比如DelegateCommand。

之所以之前想直接绑定一个ICommand的集合到MenuItem的ItemsSource上不成功,是因为MenuItem生成的Sub MenuItem的DataContext是ICommand的时候,它自己不会写Command={Binding}, 所以Command并没有绑定成功。

少了下面语句干的活。
var menuItem = new MenuItem();
command.AttachRoutedUICommand(menuItem, MenuItem.CommandProperty, " ");
menuItem.CommandParameter = nodeData;

XmlSerializer vs DataContractSerializer: Serialization in Wcf

这篇文讲得不错,可惜居然要翻墙。

摘录:

The XmlSerializer has been in .Net since version 1.0 and has served us well for everything from Remoting, Web Services, serializing to a file, etc. However in .Net 3.0 the DataContractSerializer came along.? And all of a sudden a lot of guidance suggests that we should use it over the old tried and true XmlSerializer. Wcf even uses this as the default mechanism for serialization.? The question is, “Is it really better?”.? The verdict is yes, and no.? Like most things it depends on your implementation and what you need.? For Wcf, you should prefer to use the DataContractSerializer.? If you need full control over how the xml looks though, you should go back to the XmlSerializer.

Lets look at the both of these in detail and leave it up to you to decide which is best for your implementation.? Here are a few of the advantages and disadvantages of each of them:

。。。。。。。。