我有一个简单的 Avalonia 表格:
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="AvaloniaExperiment.MainWindow"
Title="AvaloniaExperiment">
<StackPanel>
<TextBlock>Welcome to Avalonia!</TextBlock>
<Button Name="btn" Click="btn_OnClick">Fred!</Button>
</StackPanel>
</Window>
以及后面代码中的一个方法(我想以这种方式做事,直到我熟悉 Avalonia,然后也许我会尝试 MVVM):
private void btn_OnClick()
{
btn.Text = "Ginger";
}
但是我得到这些编译错误:
名称 btn 在当前上下文中不存在(在后面的代码中)
无法为参数 System.Private.CoreLib:System.String 的 Avalonia.Controls:Avalonia.Controls.Button 类型的属性 Click 找到合适的设置器或加法器,可用的设置器参数列表为:System.EventHandler`1[[Avalonia.Interactivity。 RoutedEventArgs,Avalonia.Interactivity,版本=0.9.0.0,文化=中性,PublicKeyToken=null]](在 XAML 中)
无法为参数 System.Runtime:System.String 类型的 Avalonia.Controls:Avalonia.Controls.Button 属性命令找到合适的设置器或加法器,可用的设置器参数列表为:Avalonia.UnsetValueType Avalonia.Data.IBinding System.Windows.Input .ICommand(也在 XAML 中)
在连接这个事件处理程序时我做错了什么?