2010-10-05 60 views
0

我有一個包含一年中所有月份的兩列系列的簡單圖表。我想過濾一個列表視圖,顯示所選月份的詳細信息。我可以通過上的MouseDown捕獲該事件,但我不確定如何在列系列中獲得月份。在鼠標上檢索值點擊WPF列系列

<DVC:ColumnSeries Title=" Expenditures" IndependentValueBinding="{Binding Path=Month}" 
        DependentValueBinding="{Binding Path=Amt}" 
        ItemsSource="{Binding Path=ActivityExpenditureSeries}" 
        MouseDown="ColumnSeries_MouseDown" /> 

我敢肯定,我可以做一些花哨的WPF數據綁定的列表視圖ItemsSource選擇ColumnSeries但是這是我的標題:

Private Sub ColumnSeries_MouseDown(ByVal sender As System.Object, 
            ByVal e As System.Windows.Input.MouseButtonEventArgs) 
    ' This is the functionality I'm looking for... 
    Dim selectedColumn As String 
    FilterListView(selectedColumn) 
End Sub 

回答

4

坐落在一系列IsSelectionEnabled=True並添加一個SelectionChanged事件到同一系列。

Private Sub colSeries_adjExpenditure_SelectionChanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.SelectionChangedEventArgs) 
     Dim cs As ColumnSeries = CType(sender, ColumnSeries) 
     Dim dp As MyDataPoint = CType(cs.SelectedItem, MyDataPoint) 
End Sub 
0

坐落在一系列IsSelectionEnabled=True,並添加了SelectionChanged事件同一系列。

System.Windows.Controls.DataVisualization.Charting.ColumnSeries cs = (System.Windows.Controls.DataVisualization.Charting.ColumnSeries)sender; 
System.Data.DataRowView dp = (System.Data.DataRowView)cs.SelectedItem; 
tbkName.Text = dp.Row[1].ToString(); 
tbkSalary.Text = dp.Row[0].ToString(); 
0

實施例C#:

設置在該系列中的IsSelectionEnabled=True並增加了一個SelectionChanged事件同一系列。

命名空間:

using System.Windows.Controls.DataVisualization.Charting; 

方法:

private void ColumnSeries_SelectionChanged(object sender, SelectionChangedEventArgs e) 
      { 
       ColumnSeries cs = (ColumnSeries)sender; 
       KeyValuePair<string, int> kv = (KeyValuePair<string, int>)cs.SelectedItem; 

       Debug.WriteLine(kv.Key); 
       Debug.WriteLine(kv.Value); 
      } 
0

[在C#] 以前的答案只允許時,點擊選擇的改變。以下代碼將使您可以單擊列,而不必單擊之前單擊的位置。如果需要,它也將允許右擊(改變事件類型)

<chartingToolkit:ColumnSeries DependentValuePath="Value" IndependentValuePath="Key" IsSelectionEnabled="True"> 
<chartingToolkit:ColumnSeries.DataPointStyle> 
    <Style TargetType="chartingToolkit:ColumnDataPoint"> 
     <EventSetter Event="MouseLeftButtonUp" Handler="ColumnSeries_ColumnLeftClicked"/> 
    </Style> 
</chartingToolkit:ColumnSeries.DataPointStyle> 
</chartingToolkit:ColumnSeries> 

private void ColumnSeries_ColumnLeftClicked(object sender, MouseButtonEventArgs e) 
{ 
    var key = ((ColumnDataPoint)sender).IndependentValue; 
    //etc 
}