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

发布于 2024-11-16 19:47:45 字数 3292 浏览 2 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

皓月长歌 2024-11-23 19:47:45

设置 PassEventArgsToCommand="True" 是否可以满足您的需求?例如:

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

如果您不想在定义 ViewModel 的地方引用 Telerik 程序集,则可以使用使用动态的处理程序而不是像这样的对象:

public void MyCommandHandler(dynamic args) { }

我使用此技巧来保持我的项目“干净”。 ”现在您可以在参数上调用您需要的任何内容,而无需引用任何“Telerik”。

Does setting PassEventArgsToCommand="True" work for your needs? For example:

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

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:

public void MyCommandHandler(dynamic args) { }

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."

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文