很抱歉,如果这是一个新手问题,但是,我...我已经尝试了2天了,在网上搜索并询问周围,没有人可以帮助我,所以任何见解都会不胜感激...
我基本上需要做的是在打开上下文菜单之前用rightclick选择图表系列(ColumnSeries或LineSeries)数据点。当我处理menuItemClick事件时,我需要数据点的x轴的值。理想情况下,我希望能够在rightclick和leftclick上提升SelectionChanged事件,但还没有找到任何方法。我已经尝试了一些替代方案,但仍然遇到了死胡同。这个解决方案似乎做了我想要的LineSeries:Select the nearest point in a Silverlight Toolkit chart,但我的系列中有90%是ColumnSeries而没有serie.Points属性所以我再次陷入困境......
答案 0 :(得分:0)
最后我使用了这个解决方案:http://www.c-sharpcorner.com/uploadfile/baimey/silverlight-charts-coordinates-on-mousemove/
我想我最好发布它以防万一其他人需要这个。
private void Chart_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
{
Series serie = sender as Series;
DateTime xAxisValue;
Point p = e.GetPosition(serie);
ICategoryAxis xAxis = (CategoryAxis)Chart.ActualAxes[0];
object xHit = xAxis.GetCategoryAtPosition(new UnitValue(p.X, Unit.Pixels));
if (SelectedObj != null)
{
xAxisValue = (DateTime)new DateTimeConverter().ConvertBack(xHit as String, typeof(String), SelectedObj.DisplayFrequency, Thread.CurrentThread.CurrentUICulture);
foreach (Frequency frequency in SelectedObj.Frequencies)
{
if(frequency == SelectedObj.DisplayFrequency)
addMenuItem(frequency, true, xAxisValue);
else
addMenuItem(frequency, false, xAxisValue);
}
cMenu.IsOpen = true;
cMenu.HorizontalOffset = e.GetPosition(LayoutRoot).X;
cMenu.VerticalOffset = e.GetPosition(LayoutRoot).Y;
}
}
private void addMenuItem(Frequency frequency, bool isDisplayFrequency, DateTime xAxisValue)
{
menuItem = new MenuItem();
menuItem.Header = frequency;
menuItem.Tag = xAxisValue;
if (isDisplayFrequency)
{
menuItem.Icon = new TextBlock { Text = "\xfc", FontFamily = new System.Windows.Media.FontFamily("Wingdings"), FontWeight = FontWeights.Bold, TextAlignment = TextAlignment.Center };
menuItem.FontWeight = FontWeights.Bold;
}
cMenu.Items.Add(menuItem);
menuItem.Click += new RoutedEventHandler(menuItem_Click);
}
void menuItem_Click(object sender, RoutedEventArgs e)
{
MenuItem item = sender as MenuItem;
Frequency itemFreq = (Frequency)item.Header;
DateTime xAxisValue = (DateTime)item.Tag;
...
cMenu.IsOpen = false;
}