如何绑定到不是当前绑定上下文的viewmodel上的属性

问题描述 投票:0回答:1

我有一个标签:

<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 ...”

我也尝试过另一种方式,我使用Source = x:引用与BModel,但这也不起作用。

有任何想法吗?

c# forms xamarin binding
1个回答
0
投票

所以,显然我是个白痴。看来我毕竟不需要BindingContext。现在Label看起来像这样:

<Label Text="{Binding BModel.BoundDataItem.CurrentValue.Value}"
       IsVisible="{Binding IsEditButtonShown}"/>

它似乎像它应该的那样工作。

有趣的是,当你开始向他人解释时,事情会发生在你身上。

© www.soinside.com 2019 - 2024. All rights reserved.