使用数据绑定控制Window的高度, 使用如下XMAL片段不能生效。
Height="{Binding HeightSlider.Value"}
但是如果设置为双向绑定就OK,如下
Height="{Binding HeightSlider.Value,Mode=TwoWay}"
后来发现Window的Left, Top, Height, Width都是这样的,必须使用双向绑定才行。
这是为什么?MSDN中有什么有用的信息吗?
感谢dudu的线索。
StackOverflow除了dudu提供的那个帖子外,还有两个类似的帖子,但是都没有该问题的最终的结论。
http://stackoverflow.com/questions/23426020/window-wpf-height-is-not-bound-to-the-model-property
http://stackoverflow.com/questions/28649856/window-height-and-width-binding-only-one-is-fetched-from-datacontext
参考 Problems with binding to Window Height and Width
这个回答也许是一个线索:
I had the same problem and I noticed that it depends whether height or width is written first in xaml. If height is first, then Binding work only for it and vice versa. The solution was to set Binding mode to 'TwoWay': The project I have made was with MS Studio 2010 and .NET 4.0.