我正在尝试使用 MVVM 模式绑定 LiveChart 的笛卡尔图表元素的“DataClick”事件。
我有这样的 Charts.xml:
<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>
这是我的 ViewModel 上的 ICommand ChartDataClick:
public ICommand ChartDataClick {
get
{
if(_dataClickCommand == null)
{
_dataClickCommand = new DelegateCommand(
() =>
{
MessageBox.Show("Data Clicked!");
}
);
}
return _dataClickCommand;
}
}
如果我将例如“DataClick”切换为“MouseEnter”,我会触发我的命令。
所以我假设问题在于 DataClick 是一个自定义事件。
有人知道解决方法吗?我真的尝试了所有可以在 Google 上找到的可以提供帮助的方法,但到目前为止还没有...
LiveCharts 事件:事件文档