WPF 绑定顺序 - 如何更改?
我有一个切换按钮,我将其“标签”属性绑定到一个对象。然后,我将“IsChecked”属性绑定到其“Tag”属性。 我的问题是,当窗口加载时首先调用“IsChecked”,然后调用“Tag”。 我怎样才能先绑定“标签”属性?
<ToggleButton>
<ToggleButton.Tag>
<Bind An Object...>
</ToggleButton.Tag>
<ToggleButton.IsChecked>
<Binding Converter="{StaticResource SomeConverter}" Path="Tag" RelativeSource="{RelativeSource Self}"/>
</ToggleButton.IsChecked>
</ToggleButton>
I have a toggle button which i bind its 'Tag' property to an object. I then bind the 'IsChecked' property to its 'Tag' property.
My problem is that the 'IsChecked' is called first when the window loads and the 'Tag' second.
How could i make the 'Tag' property bind first?
<ToggleButton>
<ToggleButton.Tag>
<Bind An Object...>
</ToggleButton.Tag>
<ToggleButton.IsChecked>
<Binding Converter="{StaticResource SomeConverter}" Path="Tag" RelativeSource="{RelativeSource Self}"/>
</ToggleButton.IsChecked>
</ToggleButton>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么顺序很重要?是否因为您的转换器不处理值为
null
时的情况,因为它应该处理 - 即使它返回Binding.DoNothing
。当 Tag 设置为某项时,您的 IsChecked 绑定应该刷新,并且您的转换器应该再次运行。难道不是这样吗?Why does order matter? Is it because your converter doesn't handle the case when the value is
null
, because it should - even if it returnsBinding.DoNothing
. When Tag is set to something, your IsChecked binding should refresh and your converter should run again. Is that not the case?您可以将此源(将您绑定到
Tag
的源)直接绑定到Tag
和IsChecked
,那么您就没有IsChecked
绑定依赖于Tag
并且您不关心竞争条件,也不需要任何顺序。You can bind this source (source what you binding to
Tag
) directly toTag
andIsChecked
, then you don't haveIsChecked
binding dependend onTag
and you dont care about race condition and you don't need any order.