【问题标题】:How to set a foreground color in XAML?如何在 XAML 中设置前景色?
【发布时间】:2018-04-22 20:00:25
【问题描述】:

在 Xamarin.Forms 中,如何为 XAML 中的文本框设置前景色?

我尝试了以下方法:

  <Style TargetType="{x:Type Entry}">
    <Setter Property="BackgroundColor" Value="White" />
    <Setter Property="Foreground" Value="Black" />
  </Style>

我也试过了:

  <Style TargetType="{x:Type Entry}">
    <Setter Property="BackgroundColor" Value="White" />
    <Setter Property="ForegroundColor" Value="Black" />
  </Style>

当我尝试启动应用程序时,我收到了意外的异常。

有什么想法吗?

【问题讨论】:

    标签: xaml xamarin.forms


    【解决方案1】:

    Xamarin 论坛为我回答了这个问题:

      <Style TargetType="{x:Type Entry}">
        <Setter Property="BackgroundColor" Value="White" />
        <Setter Property="TextColor" Value="Black" />
      </Style>
    

    【讨论】:

      【解决方案2】:

      xaml 控件对象的 Foreground 和 Background 属性的类型为 Brush

      <SolidColorBrush x:Key="whiteColorBrush" Color="white" />
      <Style TargetType="{x:Type Entry}">
          <Setter Property="Foreground" Value="{StaticResource whiteColorBrush}" />
      </Style>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-03-06
        • 2018-04-09
        • 2015-03-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多