这是我的代码(.NET Maui-Visual Studio):
File 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
}
}
}
File 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"/>
......
然而,我得到了一个:
编译器错误CS0120:非静态字段、方法或属性‘Color.Blue’需要对象引用
我的代码出了什么问题?