[Xamarin.Forms] SearchBarでプレースホルダの色を設定するには?

スポンサーリンク

SearchHolderのプレースホルダの色を設定するには PlaceholderColor プロパティを使用します。

以下はXamlにおける PlaceholderColor プロパティの使用例です(12行目)。

<?xml version="1.0" encoding="utf-8"?>
<ContentPage 
    xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:searchBarSample03"
    x:Class="searchBarSample03.MainPage"
    xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
    ios:Page.UseSafeArea="true">
    
    <StackLayout>
        
        <SearchBar x:Name="searchBar" Placeholder="検索文字列" PlaceholderColor="Red" />
        
    </StackLayout>
</ContentPage>

コードで プレースホルダの色を設定するには、以下のようにします。

namespace searchBarSample03
{
  public partial class MainPage : ContentPage
  {
      public MainPage()
      {
          InitializeComponent();

          searchBar.Placeholder = "検索文字列";
          searchBar.PlaceholderColor = Color.Red;
      }
  }
}

実行例を以下に示します。

 

Please follow and like us:

コメント

タイトルとURLをコピーしました