在设计界面时,通常都编写一个配置方法(如SetZoomPan),在窗体载入时调用进行默认的设置(参数为空),如果需要修改则单独调用,并传递一个指定的配置对象。希望用指定的配置对象覆盖默认的设置。
SetZoomPan(new ZoomPanOptions3D
{
RotationSensitivity=12
});
具体方法的实现
public void SetZoomPan(ZoomPanOptions3D options=null)
{
_lightningChart.View3D.ZoomPanOptions.AutoFit = options?.AutoFit ?? true;
_lightningChart.View3D.ZoomPanOptions.LeftMouseButtonAction = options?.LeftMouseButtonAction ?? MouseButtonAction3D.Rotate;
_lightningChart.View3D.ZoomPanOptions.RotationSensitivity = options?.RotationSensitivity ?? 1;
// _lightningChart.View3D.ZoomPanOptions.MiddleMouseButtonAction = MouseButtonAction3D.ZoomX;
_lightningChart.View3D.ZoomPanOptions.MouseWheelZoomEnabled = true;
_lightningChart.View3D.ZoomPanOptions.MouseWheelZoomFactor = 1.2;
_lightningChart.View3D.ZoomPanOptions.RightMouseButtonAction = MouseButtonAction3D.Pan;
_lightningChart.View3D.ZoomPanOptions.PanSensitivity = 20;
}
要点:
(1)定义默认参数options=null,用户在调用的时候可以不用填写参数
(2)_lightningChart.View3D.ZoomPanOptions.AutoFit = options?.AutoFit ?? true; 等同于
if(options!=null){
if(options.AutoFit==null){
_lightningChart.View3D.ZoomPanOptions.AutoFit =true;
}else{
_lightningChart.View3D.ZoomPanOptions.AutoFit =options.AutoFit;
}
}