你好,我需要在chart控件上画两条竖直的线,并添加拖动事件,下面是我的代码。我的问题是怎么控制chartpanel的大小,bdr的width只能控制显示的大小,我发现chartpanel占满了整个chart。这样的画,我只能控制最新添加的线,老的被覆盖了。
var obj = new ChartPanelObject()
{
Action = ChartPanelAction.LeftMouseButtonDrag,
HorizontalAlignment = System.Windows.HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Stretch
};
var bdr = new Border()
{
// Background = new SolidColorBrush(Colors.Red) { Opacity = 0.4 },
BorderBrush = new SolidColorBrush(Colors.Red),
Width = 40,
BorderThickness = new Thickness(1, 1, 1, 1),
};
obj.Content = bdr;
obj.DataPoint = new System.Windows.Point(0.3, double.NaN);
obj.Action = ChartPanelAction.LeftMouseButtonDrag;
var obj1 = new ChartPanelObject()
{
Action = ChartPanelAction.LeftMouseButtonDrag,
HorizontalAlignment = System.Windows.HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Stretch
};
var bdr1 = new Border()
{
// Background = new SolidColorBrush(Colors.Red) { Opacity = 0.4 },
BorderBrush = new SolidColorBrush(Colors.Blue),
Width = 40,
BorderThickness = new Thickness(1, 1, 1, 1),
};
obj1.Content = bdr1;
obj1.DataPoint = new System.Windows.Point(0.6, double.NaN);
var pnl = new ChartPanel();
var pnl1 = new ChartPanel();
pnl.Children.Add(obj);
pnl1.Children.Add(obj1);
_chart.View.Layers.Add(pnl);
_chart.View.Layers.Add(pnl1);
pnl.AddHandler(System.Windows.Controls.Button.MouseLeftButtonDownEvent, new MouseButtonEventHandler(Element_MouseLeftButtonDown), true);
pnl.AddHandler(System.Windows.Controls.Button.MouseMoveEvent, new System.Windows.Input.MouseEventHandler(Element_MouseMove), true);
pnl.AddHandler(System.Windows.Controls.Button.MouseLeftButtonUpEvent, new MouseButtonEventHandler(Element_MouseLeftButtonUp), true);
pnl.MouseMove += new System.Windows.Input.MouseEventHandler(Element_MouseMove);
pnl.MouseLeftButtonDown += new MouseButtonEventHandler(Element_MouseLeftButtonDown);
pnl.MouseLeftButtonUp += new MouseButtonEventHandler(Element_MouseLeftButtonUp);
pnl1.AddHandler(System.Windows.Controls.Button.MouseLeftButtonDownEvent, new MouseButtonEventHandler(Element_MouseLeftButtonDown), true);
pnl1.AddHandler(System.Windows.Controls.Button.MouseMoveEvent, new System.Windows.Input.MouseEventHandler(Element_MouseMove), true);
pnl1.AddHandler(System.Windows.Controls.Button.MouseLeftButtonUpEvent, new MouseButtonEventHandler(Element_MouseLeftButtonUp), true);
pnl1.MouseMove += new System.Windows.Input.MouseEventHandler(Element_MouseMove);
pnl1.MouseLeftButtonDown += new MouseButtonEventHandler(Element_MouseLeftButtonDown);
pnl1.MouseLeftButtonUp += new MouseButtonEventHandler(Element_MouseLeftButtonUp); |
|