gpt4 book ai didi

c# - Avalonia 按钮单击事件不起作用

转载 作者:行者123 更新时间:2023-12-04 15:28:09 31 4
gpt4 key购买 nike

我有一个简单的 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";
}

但是我收到这些编译错误:

The name btn does not exist in the current context (in the code behind)

Unable to find suitable setter or adder for property Click of type Avalonia.Controls:Avalonia.Controls.Button for argument System.Private.CoreLib:System.String, available setter parameter lists are: System.EventHandler`1[[Avalonia.Interactivity.RoutedEventArgs, Avalonia.Interactivity, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null]] (in the XAML)

Unable to find suitable setter or adder for property Command of type Avalonia.Controls:Avalonia.Controls.Button for argument System.Runtime:System.String, available setter parameter lists are: Avalonia.UnsetValueType Avalonia.Data.IBinding System.Windows.Input.ICommand (also in the XAML)



连接此事件处理程序时我会做错什么?

最佳答案

你有没有尝试过...

public void btn_OnClick(object sender, RoutedEventArgs e)
{
btn.Text = "Ginger";
}

关于c# - Avalonia 按钮单击事件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61844734/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com