Xamarin表单 - 标签TextColor不会通过Binding更新

时间:2016-10-21 11:17:16

标签: c# xaml binding textcolor

所以,基本上,我有一个Button列表。当您单击其中一个时,其Label TextColor会发生变化。为了实现它,我使用{Binding value}然而,它不起作用..我试图抛出一个事件但是......没有任何反应..我试图直接从Label中设置它工作..为什么?

我在C#部分中有这段代码:

private Color GroupSuperModLabelColor { get; set; }
private void OnGroupsClicked(object sender, EventArgs ea)
{
    if (GroupSuperModLabelColor == App.NL_White)
        GroupSuperModLabelColor = App.NL_OrangeBeer;
    else
        GroupSuperModLabelColor = App.NL_White;
    this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(GroupSuperModLabelColor)));

    //If I don't add this line, then it doesn't work, WHY?
    GroupLabel.TextColor = GroupSuperModLabelColor;

    Debug.WriteLine("OnGroupsClicked clicked !");
}

XAML部分的声明:

<AbsoluteLayout HeightRequest="{Binding SuperModHeightSize}" WidthRequest="{Binding SuperModWidthSize}">
  <control:CustomLabel x:Name="GroupLabel" Text="Groups" FontFamily="{extension:FontFamily Roboto_Light}" FontSize="20" TextColor="{Binding GroupSuperModLabelColor}"
                       HorizontalTextAlignment="Center" VerticalTextAlignment="Center"
                       AbsoluteLayout.LayoutBounds="0.5, 0.5, 1, 1"
                       AbsoluteLayout.LayoutFlags="All"/>
  <control:CustomButton BackgroundColor="Transparent" BorderColor="Transparent"
                        Clicked="OnGroupsClicked" LongPress="OnGroupsLongPress"
                        AbsoluteLayout.LayoutBounds="0.5, 0.5, 1, 1"
                        AbsoluteLayout.LayoutFlags="All"/>
  </AbsoluteLayout>

我的Binding上下文设置为this,其他所有Binding事物都有效..它只是用颜色,它似乎不起作用..

为什么呢?提前谢谢

1 个答案:

答案 0 :(得分:1)

您的GroupSuperModLabelColor未被声明为可绑定属性:the contract

您必须更改声明。