![](/img/trans.png)
[英]WPF, Caliburn.micro : How to bind property outside of current binding context?
[英]How to bind to property on viewmodel that is not the current binding context
我有一個標簽:
<Label BindingContext="{Binding BModel}"
Text="{Binding BoundDataItem.CurrentValue.Value}"
IsVisible="{Binding IsEditButtonShown}"/>
沒有Binding上下文,IsVisible屬性將按其應有的方式工作,但是現在我需要具有特定數據段的綁定上下文,但是我仍然需要IsVisible屬性才能工作。 IsEditButtonShown是我的視圖模型上的一個屬性。
我努力了:
IsVisible="{Binding IsEditButtonShown, Source={x:Reference CurrentPagename}}
什么也沒做
IsVisible="{Binding IsEditButtonShown, Source={x:Reference CurrentViewModel}}
出現有關無法找到ViewModel的錯誤(這是在將它添加到具有xmlns:viewmodel =“ clr-namespace ...”的頂部頁面之后。
我還嘗試了另一種方法,即在BModel中使用Source = x:Reference,但這也不起作用。
有任何想法嗎?
所以,顯然我是個白痴。 看來我真的並不需要該項目的BindingContext。 現在,標簽如下所示:
<Label Text="{Binding BModel.BoundDataItem.CurrentValue.Value}"
IsVisible="{Binding IsEditButtonShown}"/>
它似乎按預期工作。
當您開始向他人解釋時,事情會變得有趣。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.