在DataContext中使用Visibilty在Button中不起作用 [英] Using Visibilty with DataContext doesn't work in Button

查看:102
本文介绍了在DataContext中使用Visibilty在Button中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Button,我试图添加一个Visibility属性绑定到一个特定的路径。在大多数情况下,这个路径将被调用,我返回一个Visibilty(隐藏或可见)。如果我有一个将DataContext设置为不同绑定路径的按钮,并尝试添加Visiblity内容,则可见绑定路径永远不会被调用。如果我删除DataContext,那么Visibilty工作正常。有没有一些工作呢?为什么会发生这种情况?非常感谢。

 < Button Visibility ={Binding Path = ThisButtonVisibility}
DataContext = {Binding Path = ThisButtonDataContext}


解决方案

将DataContext绑定到隐含来源。所以你的作业是不正确的,因为Binding表达式将寻找DataContext,它是绑定到DataContext来寻找DataContext,它是Binding,一次又一次地...;)


I have a Button where I am trying to add a Visibility attribute which binds to a certain path. In most cases this path will be call and I return a Visibilty(Hidden or Visible). If I have a button that has a DataContext set to a different binded path and try to add the Visiblity stuff, the visibilty binded path never gets called. If I remove the DataContext then the Visibilty works fine. Is there some kind of work around for this? Why does this happen? Thank you very very much.

<Button Visibility="{Binding Path=ThisButtonVisibility}"
        DataContext="{Binding Path=ThisButtonDataContext}"

解决方案

Binding use DataContext as implicit source. So your assignment is incorrect, because Binding expression will look for DataContext which is Binding to DataContext to look for DataContext which is Binding and again and again... ;)

这篇关于在DataContext中使用Visibilty在Button中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆