Hello this is my code (.NET Maui – VS)
Mainpage.xaml.cs:
using System.ComponentModel;
using System.Windows.Input;
using Microsoft.Maui.Controls;
namespace App;
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
......
private void LockerClicked(object sender, EventArgs e)
{
Button clickedButton = (Button)sender;
if (clickedButton.BackgroundColor == Color.Blue)
{
// Action
}
}
}
Mainpage.cs:
......
<Button x:Name="LockerButton" Clicked="LockerClicked" Text="⌨" Grid.Row="3" Grid.Column="2" FontSize="40" TextColor="#007070" FontAttributes="Bold" CornerRadius="100" BackgroundColor="White"/>
......
However, I get a Compiler Error CS0120: An object reference is required for the nonstatic field, method, or property ‘Color.Blue’.
What is wrong with my code? Thank you in advance!
>Solution :
you need to use Colors, not Color
if (clickedButton.BackgroundColor == Colors.Blue)