VB.NET, C#, PowerShellを使用しているエンジニアのためのサイト。
基本的な使用方法から開発で役立つTipsまで幅広く取り扱っています。
Update 2018/12/23
< Prev Tips
Next Tips>
Button の背景色を変更するには BackgroundColorプロパティを使用します。
以下にコードビハインドでButtonの背景色を変更する例を示します。
xaml側では、Buttonコントロールに「button1」「button2」という名前がついているものとします。
button1は背景色を赤に、button2は背景色を青に設定しています。
Color.Redのように指定することも、Color.FromHexメソッドを使用して16進数で指定することもできます。
namespace buttonSample06
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
button1.BackgroundColor = Color.Red;
button2.BackgroundColor = Color.FromHex("00000FF");
}
}
}
次にXamlでButtonの背景色を変更する例を示します。
<Button Text=" 赤 " BackgroundColor="Red" />
<Button Text=" 青 " BackgroundColor="#0000FF" />
実行例を以下に示します。