C1Chart for WPF 提供了强大、丰富的界面元素、动态和数据绑定功能。这个控件拥有和最终用户交互的内置功能。最终用户可以使用Mouse和 Shift 键配合使用来搜索、旋转和缩放 C1Chart。有很多用户向我们询问,如何添加C1WPFChart 快捷键。这篇文章将阐述如何实现这个 Case。这种方法非常简单。手动的设置焦点到C1Chart 后你可以控制 keyboard 事件同时添加相应代码来实现快捷键的添加。但是,定制的快捷键并非是全局的,必须在 C1Chart 获得焦点的情况下才起作用。
在本文章中,我们将展示使用KeyDown/KeyUp 来实现缩放功能。实现代码如下:
Private Sub Chart1_MouseLeftButtonDown(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs Handles Chart1.MouseLeftButtonDown
'Setting the Focus manually.
'Without forcing this Focus, the keyboard events are not recognised.
Chart1.Focus()
End Sub
Private Sub Chart1_PreviewKeyDown(ByVal sender As Object, ByVal e As System.Windows.Input.KeyEventArgs) Handles Chart1.<span>PreviewKeyDown
Chart1.View.AxisX.MinScale = 0.001
Chart1.View.AxisY.MinScale = 0.001
'Checking the pressed key
If e.Key = Key.Down Then
Chart1.BeginUpdate()
'Decreasing the scale values in order to ZoomIn
Chart1.View.AxisX.Scale = Chart1.View.AxisX.Scale - 0.35
Chart1.View.AxisY.Scale = Chart1.View.AxisY.Scale - 0.35
UpdateScrollbars()
Chart1.EndUpdate()
ElseIf e.Key = Key.Up Then
Chart1.BeginUpdate()
'Increasing the scale values in order to ZoomOut
Chart1.View.AxisX.scale = Chart1.View.AxisX.Scale + 0.35
Chart1.View.AxisY.Scale = Chart1.View.AxisY.Scale + 0.35
UpdateScrollbars()
Chart1.EndUpdate()
ElseIf e.Key = Key.Escape Then
Chart1.BeginUpdate()
'Setting the Scale to Default Value
Chart1.View.AxisX.Scale = 1
Chart1.View.AxisY.Scale = 1
UpdateScrollbars()
Chart1.EndUpdate()
End If
End Sub