Silverlight Telerik Chart单击事件值作为Command参数

时间:2011-06-21 12:21:18

标签: .net silverlight silverlight-4.0 telerik telerik-grid

我有一个Telerik Silverlight RadChart,当用户点击其中一个条形并使用MVVMLight RelayCommand将底层值传递给ViewModel时,我想捕获ItemClick事件。

我遇到的问题是我不知道如何将值传递给CommandParameter。

XAML

<telerik:RadChart x:Name="Chart" Grid.Row="1" ItemsSource="{Binding Path=ConcernsCounts}">
    <telerik:RadChart.SeriesMappings>
        <telerik:SeriesMapping>
            <telerik:SeriesMapping.SeriesDefinition>
                <telerik:BarSeriesDefinition ShowItemToolTips="True" />
            </telerik:SeriesMapping.SeriesDefinition>
            <telerik:ItemMapping FieldName="ConcernsCount" DataPointMember="LegendLabel"/>
            <telerik:ItemMapping FieldName="BusinessUnit" DataPointMember="XCategory"/>
            <telerik:ItemMapping FieldName="ConcernsCount" DataPointMember="Label"/>
            <telerik:ItemMapping FieldName="ConcernsCount" DataPointMember="YValue"/>
        </telerik:SeriesMapping>
    </telerik:RadChart.SeriesMappings>
    <telerik:RadChart.DefaultView>
        <telerik:ChartDefaultView>
            <telerik:ChartDefaultView.ChartTitle>
                <telerik:ChartTitle Content="PLM Concerns By Business Unit" HorizontalAlignment="Center"/>                           
            </telerik:ChartDefaultView.ChartTitle>
            <telerik:ChartDefaultView.ChartLegend>
                <telerik:ChartLegend x:Name="ChartLegend" UseAutoGeneratedItems="True" Visibility="Collapsed"/>
            </telerik:ChartDefaultView.ChartLegend>                   
            <telerik:ChartDefaultView.ChartArea>
                <telerik:ChartArea LegendName="ChartLegend" Name="BusinessChartArea">
                    <telerik:ChartArea.AxisX>
                        <telerik:AxisX LabelRotationAngle="45"/>
                    </telerik:ChartArea.AxisX>
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="ItemClick">
                            <cmd:EventToCommand Command="{Binding LoadDetails}" CommandParameter="{Binding ?????? />
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </telerik:ChartArea>
            </telerik:ChartDefaultView.ChartArea>
        </telerik:ChartDefaultView>
    </telerik:RadChart.DefaultView>
</telerik:RadChart>

我可以在后面的代码中捕获事件,但更愿意明确地执行任务

背后的代码

Partial Public Class ConcernsView
    Inherits Page

    Public Sub New()
        InitializeComponent()


        ' Add any initialization after the InitializeComponent() call.
        AddHandler Chart.DefaultView.ChartArea.ItemClick, Sub(s, e) stopMe(s, e)
    End Sub

    'Executes when the user navigates to this page.
    Protected Overrides Sub OnNavigatedTo(ByVal e As System.Windows.Navigation.NavigationEventArgs)

    End Sub

    Private Function stopMe(ByVal sender As Object, ByVal e As Telerik.Windows.Controls.Charting.ChartItemClickEventArgs) As Object
        Dim sss As String
        sss = e.DataPoint.XCategory
        Stop
    End Function

End Class

如何在命令绑定中做到这一点??

由于

菲尔

1 个答案:

答案 0 :(得分:0)

设置PassEventArgsToCommand =“True”是否适合您的需求?例如:

<i:EventTrigger EventName="ItemClick">
    <cmd:EventToCommand Command="{Binding LoadDetails}" PassEventArgsToCommand="True" />
</i:EventTrigger>

如果您不希望对定义了ViewModel的Telerik程序集进行引用,则可以使用动态处理程序而不是像这样的对象:

public void MyCommandHandler(dynamic args) { }

我使用这个技巧来保持我的项目“干净”。现在你可以在args上调用你需要的任何东西,而不必引用任何“Telerik”。