2016-10-11 1 views
4

MVVMパターンを使用してLiveChartのデカルトチャート要素の "DataClick"イベントをバインドしようとしています。MVVMパターンでカスタム要素のカスタムイベントをバインドする

私はこのように私の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; 
     } 
    } 

私は "MouseEnterイベント" のために例えば "DataClick" を切り替えると、私は私の取得命令は発砲した。

私は、問題は、DataClickがカスタムイベントであると仮定しています。

誰もがこの回避策を知っていますか? 私は本当に私が助けることができるGoogleで見つけることができるすべてのものを試してみましたが、何も今のところ...

LiveChartsイベントは:Events Documentation

+1

これは最終的にサポートされています... https://github.com/beto-rodriguez/Live-Charts/issues/42 –

答えて

2

EventTriggerは区別しません。

これは、カスタムルーティングイベントTapを持つMyButtonSimpleを実装することで確認できます。

我々は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> 

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

の後ろにコードでハンドラから行くことができ、すべてが期待どおりにこれらのトリガーの欠点は、彼らがしなければならないことである

の作品UIElementに置いてイベントを起こした。 つまり、BubblingイベントまたはTunnelingイベントは無視されます。

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

それを要約すると、DataClickイベントがCartesianChart(しかし、さらに論理ツリーダウン)で発生されていないので、あなたはそれをこのように扱うことができません:それはのためのInteraction.Triggers選択肢がない理由です。

+0

私はこのイベントを処理することができません。それともヘルパーなどで可能だと思いますか?私がLiveChartsのコードを変更して、ルーティングされた 'DataClick'イベントを生成すると、違いはありますか? –

関連する問題