我使用silverlight创建了一个气泡图,如下所示:
<charting:Chart Title="Bubble Chart"
LegendTitle="Legend"
Name="chart1" Margin="0,0,0,42"
HorizontalAlignment="Left" Width="568">
<charting:Chart.Series>
<charting:BubbleSeries Title="Pollutant A" IsSelectionEnabled="True"
ItemsSource="{Binding Pollution}"
IndependentValuePath="AQI"
DependentValuePath="Level"
SelectionChanged="ChangeSomething"
SizeValuePath="size1" >
</charting:BubbleSeries>
</charting:Chart>
我的xaml.cs定义了这样的处理程序:
private void ChangeSomething(object sender, SelectionChangedEventArgs e){
Text1.text="selection changed"
// Here I want to show the value of the bubble selected
}
有人可以告诉我怎么做?谢谢:)
答案 0 :(得分:1)
SelectionChangedEventArgs
参数将包含一个名为AddedItems
的属性,这是在此更改期间已添加到所选项目的ItemsSource
项目的列表。大部分时间只有一个,它是刚刚选择的项目。
为了示例,我将为您的事件提供模型中Pollution
属性返回的对象的类型名称。我会给出类型名称PollutionSample
(当然我只是在这里猜测)。
因此,您可以像这样访问所选的PollutionSample
: -
private void ChangeSomething(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems.Count > 0)
{
PollutionSample ps = e.AddedItems[0] as PollutionSample;
if (ps != null)
{
// Do something with sample
}
}
}