How can i use EventArgsConverter in prism InvokeCommandAction?

Viewed 120
1 Answers

The b: is the xmlns reference to xaml behaviors which is now a nuget package

See

https://devblogs.microsoft.com/dotnet/open-sourcing-xaml-behaviors-for-wpf/

As in

 xmlns:b="http://schemas.microsoft.com/xaml/behaviors"

Working markup and code:

        xmlns:b="http://schemas.microsoft.com/xaml/behaviors">
    <Window.DataContext>
        <local:MainWindowViewModel/>
    </Window.DataContext>

    <Grid>
        <Button>
            <b:Interaction.Triggers>
                <b:EventTrigger EventName="Click">
                    <b:InvokeCommandAction Command="{Binding TestCommand}" />
                </b:EventTrigger>
            </b:Interaction.Triggers>
        </Button>
    </Grid>
</Window>

Viewmodel:

    public class MainWindowViewModel
    {
        private ICommand _testCommand;
        public ICommand TestCommand
        {
            get
            {
                if (_testCommand == null)
                {
                    _testCommand = new RelayCommand(
                        p => true,
                        p => this.TestMethod());
                }
                return _testCommand;
            }
        }
        public void TestMethod()
        {
            MessageBox.Show("It worked !!!");
        }
    }

When I click the button, the messagebox appears.

Related