3 回答

TA贡献1934条经验 获得超2个赞
这是WPF的限制,它是设计使然。在Connect上有报道,这里:
只读依赖项属性的OneWayToSource绑定
我提出了一个解决方案,可以动态地将只读的依赖项属性推到PushBinding我在此处写过博客的源中。下面的例子不OneWayToSource绑定从只读DP的ActualWidth和ActualHeight到的宽度和高度属性DataContext
<TextBlock Name="myTextBlock">
<pb:PushBindingManager.PushBindings>
<pb:PushBinding TargetProperty="ActualHeight" Path="Height"/>
<pb:PushBinding TargetProperty="ActualWidth" Path="Width"/>
</pb:PushBindingManager.PushBindings>
</TextBlock>
PushBinding通过使用两个依赖项属性Listener和Mirror来工作。侦听器绑定OneWay到TargetProperty,并在PropertyChangedCallback其中更新Mirror属性,该属性绑定OneWayToSource到Binding中指定的任何内容。
演示项目可以在这里下载。
它包含源代码和简短的示例用法,如果您对实现细节感兴趣,请访问我的WPF博客。
- 3 回答
- 0 关注
- 968 浏览
相关问题推荐
添加回答
举报