Avalonia 模板里面绑定ViewModel跟WPF写法有些不同。需要单独绑定Command.
WPF里面可以直接按照下面的方法绑定DataContext.
<Button Content="Button"
Command="{Binding DataContext.ClickCommand, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" CommandParameter="{Binding ID}" />
Avalonia得改成下面这样,单独写Command,在DataContexe前面要加上对应VIewMode强制转换。
<DataTemplate >
<Button
CommandParameter="{Binding Value}"
Content="{Binding Label}">
<Button.Command>
<Binding Path="((vm:MessagViewModel)DataContext).ButtonClicked" RelativeSource="{RelativeSource AncestorType=Window}" />
</Button.Command>
</Button>
</DataTemplate>