【问题标题】:How to bind to property on viewmodel that is not the current binding context如何绑定到不是当前绑定上下文的视图模型上的属性
【发布时间】:2019-01-24 15:44:17
【问题描述】:

我有一个标签:

<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:Reference 与 BModel 一起使用,但这也不起作用。

有什么想法吗?

【问题讨论】:

    标签: c# forms xamarin binding


    【解决方案1】:

    所以,显然我是个白痴。毕竟我似乎并不真的需要那个项目的 BindingContext。现在标签看起来像这样:

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

    它看起来像它应该的那样工作。

    当你开始向别人解释事情时,你会觉得很有趣。

    【讨论】:

      猜你喜欢
      • 2012-03-17
      • 2010-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多