Silverlight Telerik Chart 单击事件值作为命令参数
我有一个 Telerik Silverlight RadChart,我想在用户单击其中一个栏时捕获 ItemClick 事件,并使用 MVVMLight RelayCommand 将基础值传递到 ViewModel。
我遇到的问题是我不知道如何将值传递给 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
知道如何在命令绑定中执行此操作吗?
谢谢菲尔
I have a Telerik Silverlight RadChart and I would like to capture the ItemClick event when the use clicks on one of the bars and pass the underlying value through to a ViewModel using a MVVMLight RelayCommand.
The problem I have is that I do not know how to pass through the value to the 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>
I can capture the event in the code behind but would prefer to do the task declaritively
Code Behind
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
Any idea of how to do this in the Command binding??
Thanks
Phil
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
设置 PassEventArgsToCommand="True" 是否可以满足您的需求?例如:
如果您不想在定义 ViewModel 的地方引用 Telerik 程序集,则可以使用使用动态的处理程序而不是像这样的对象:
我使用此技巧来保持我的项目“干净”。 ”现在您可以在参数上调用您需要的任何内容,而无需引用任何“Telerik”。
Does setting PassEventArgsToCommand="True" work for your needs? For example:
If you don't want to have a reference to the Telerik assemblies where ever your ViewModel is defined, you can use a handler using a dynamic instead of an object like this:
I use this trick to keep my projects "clean." Now you can call whatever you need on the args without having to reference anything "Telerik."