Binding custom events to custom elements in the MVVM template

I am trying to bind a DataClick event of a Carteian Chart LiveChart element using the MVVM template.

I have my own Charts.xml like this:

<ContentControl Grid.Row="0">
        <lvc:CartesianChart x:Name="ContrastChart" Series="{Binding ContrastSeriesCollection}">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="DataClick">
                    <i:InvokeCommandAction Command="{Binding ChartDataClick}" />
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </lvc:CartesianChart>
    </ContentControl>

This is my ICommand ChartDataClick on my ViewModel:

        public ICommand ChartDataClick {
        get
        {
            if(_dataClickCommand == null)
            {
                _dataClickCommand = new DelegateCommand( 
                    () => 
                    {
                        MessageBox.Show("Data Clicked!");
                    } 
                    );
            }

            return _dataClickCommand;
        }
    }

If I switch, for example, "DataClick" for "MouseEnter", I run my command.

So, I guess the problem is that DataClick is a custom event.

Does anyone know a workaround for this? I really tried everything I could find on Google that could help, but nothing so far ...

LiveCharts Events: Event Documentation

+4
1

EventTrigger .

, MyButtonSimple, Tap.

<custom:MyButtonSimple 
    x:Name="mybtnsimple" Tap="mybtnsimple_Tap"
    Content="Click to see Tap custom event work">
</custom:MyButtonSimple>

To ViewModel ICommand

<custom:MyButtonSimple 
    x:Name="mybtnsimple"  
    Content="Click to see Tap custom event work">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Tap">
            <i:InvokeCommandAction Command="{Binding Command}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
</custom:MyButtonSimple>

, UIElement, . , Bubbling Tunneling. Interaction.Triggers :

<Grid custom:MyButtonSimple.Tap="mybtnsimple_Tap">
    <custom:MyButtonSimple 
        x:Name="mybtnsimple"  
        Content="Click to see Tap custom event work">
    </custom:MyButtonSimple>
</Grid>

, DataClick CartesianChart ( ), .

+2

Source: https://habr.com/ru/post/1657382/


All Articles