Closed Avngarde closed 5 years ago
I am not sure about Avalonia, but in WPF and UWP Binding doesn't support event handlers as Command value (except x:Bind in UWP, but it is special). So you need use just Click="OnButtonClick" without commands.
Or create property of type ICommand, for example:
public ICommand ButtonClickCommand { get; }
Command="{Binding ButtonClickCommand}"
You should also implement ICommand or find some MVVM framework with it. Something like ReactiveUI.
So i should rather implement the command in ViewModel with ReactiveUI than in view?
@ShamanDev for MVVM - yes, commands should be defined in ViewModel.
I think i found the real issue here. Command makes my button grayed out when it's part of ItemsPresenter, yet implementing command in ViewModel with ReactiveUI works for buttons outside of it.
Can we reopen this? I have the same issue. I am using MvvmToolkit to create my commands.
ViewModel c#
[RelayCommand]
private async Task StartRecorderAsync()
and then in xaml
<Button Content="Start" Command="{Binding StartRecorderCommand}"/>
This will result in a grayed-out button in the VS22 UI preview
Use CompiledBindings
I do use compile bindings.
my current workaround to enable buttons in UI preview is to add Priority
like this:
<Button Content="Start" Command="{Binding StartRecorderCommand, Priority=1}"/>
Please open a new Q&A with a sample attached. I'll not reopen such an old issue, must be something similar but not the exact same thing. Thx.
Hello! There's an issue i couldn't find solution for. When i add a command to a button it becomes grayed out, and it's not click able.
<Button Width="80" Height="50" HorizontalAlignment="Right" VerticalAlignment="Center" IsEnabled="True" Margin="0,0,10,0" Command="{Binding OnButtonClick}">Play now</Button>
private void OnButtonClick(object sender, RoutedEventArgs e) { Console.WriteLine("Played!"); }