【发布时间】:2020-01-27 18:43:55
【问题描述】:
我正在使用 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 时没有任何反应?这是为什么?我想将Message 的文本更新为Hello world!,但没有任何反应。
为什么会这样,我的错误在哪里?
【问题讨论】:
-
点击按钮时是否会触发
UpdateText方法? -
我不知道如何测试。
-
只要在方法入口处放断点
-
看起来是进去了,但没有改变文字...
-
我没有使用 Avalonia,但我猜 Text 必须是一个属性,可能带有一些更改通知
标签: c# wpf avaloniaui