我正在使用 Avalonia 0.9.2。
我对它很陌生,按下按钮时我无法更改文本。
这是我的MainWindow.xaml
:
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:ReadyForWar_Launcher.ViewModels;assembly=ReadyForWar_Launcher"
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="ReadyForWar_Launcher.Views.MainWindow"
Icon="/Assets/avalonia-logo.ico"
Title="ReadyForWar_Launcher">
<Design.DataContext>
<vm:MainWindowViewModel/>
</Design.DataContext>
<StackPanel>
<Button Content="Update the Text" Command="{Binding UpdateText}" CommandParameter="Hello World!"></Button>
<TextBlock Text="{Binding Message}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</StackPanel>
</Window>
这是我的MainWindowViewModel
:
public class MainWindowViewModel : ViewModelBase
{
public string Message = "Welcome to Avalonia!";
public void UpdateText(object text)
{
Message = (string)text;
}
}
当我单击按钮Update the Text
时没有任何反应?这是为什么?我想更新 to 的文本,Message
但Hello world!
没有任何反应。
为什么会这样,我的错误在哪里?