【问题标题】:Xamarin binding Reference is it needed for every element?每个元素都需要 Xamarin 绑定参考吗?
【发布时间】:2017-07-07 15:35:43
【问题描述】:

我的应用程序中有此代码:

<StackLayout x:Name="pfs" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">

   <StackLayout Grid.Row="0" Grid.Column="1" Padding="0,0,20,0" Orientation="Horizontal"
      HorizontalOptions="EndAndExpand" VerticalOptions="CenterAndExpand">
      <Label x:Name="scoreCountLabel" 
        TextColor="{Binding BindingContext.TickMarkColor, Source={Reference pfs}}"/>
   </StackLayout>

我想了解 TextColor 是如何设置的。有人可以向我解释为什么开发人员设置了 Source={Reference pfs}

为什么需要它,因为它已经在名为 pfs 的 StackLayout 中?

【问题讨论】:

    标签: xamarin xamarin.forms


    【解决方案1】:

    据我所知,这完全没有必要。 BindingContext 被所有子视图继承,所以引用父视图的 BindingContext 是多余的。

    TextColor="{Binding TickMarkColor}"/>
    

    完成。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-13
      • 1970-01-01
      • 2022-01-08
      • 1970-01-01
      相关资源
      最近更新 更多