{"record":{"id":"076707a1c38421f7","repo":"HandyOrg/HandyControl","slug":"nameof-window-null","errorCode":null,"errorMessage":"{nameof(window)} 不能为 null","messagePattern":"(.+?) 不能为 null","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Shared/HandyControl_Shared/Tools/Helper/FullScreenHelper.cs","lineNumber":41,"sourceCode":"\n    /// <summary>\n    /// 用于记录窗口全屏前样式的附加属性\n    /// </summary>\n    private static readonly DependencyProperty BeforeFullScreenWindowStyleProperty =\n        DependencyProperty.RegisterAttached(\"BeforeFullScreenWindowStyle\",\n            typeof(InteropValues.WindowStyles?), typeof(FullScreenHelper));\n\n    /// <summary>\n    /// 开始进入全屏模式\n    /// 进入全屏模式后，窗口可通过 API 方式（也可以用 Win + Shift + Left/Right）移动，调整大小，但会根据目标矩形寻找显示器重新调整到全屏状态。\n    /// 进入全屏后，不要修改样式等窗口属性，在退出时，会恢复到进入前的状态\n    /// 进入全屏模式后会禁用 DWM 过渡动画\n    /// </summary>\n    public static void StartFullScreen(System.Windows.Window window)\n    {\n        if (window == null)\n        {\n            throw new ArgumentNullException(nameof(window), $\"{nameof(window)} 不能为 null\");\n        }\n\n        //确保不在全屏模式\n        if (window.GetValue(BeforeFullScreenWindowPlacementProperty) == null &&\n            window.GetValue(BeforeFullScreenWindowStyleProperty) == null)\n        {\n            var hwnd = new WindowInteropHelper(window).EnsureHandle();\n            var hwndSource = HwndSource.FromHwnd(hwnd);\n\n            //获取当前窗口的位置大小状态并保存\n            var placement = InteropMethods.GetWindowPlacement(hwnd);\n            window.SetValue(BeforeFullScreenWindowPlacementProperty, placement);\n\n            //修改窗口样式\n            var style = (InteropValues.WindowStyles) InteropMethods.GetWindowLongPtr(hwnd, InteropValues.GWL_STYLE);\n            window.SetValue(BeforeFullScreenWindowStyleProperty, style);\n            //将窗口恢复到还原模式，在有标题栏的情况下最大化模式下无法全屏,\n            //这里采用还原，不修改标题栏的方式","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/HandyOrg/HandyControl/blob/2c0875ebd67326e0c67282967e3e809c69282fee/src/Shared/HandyControl_Shared/Tools/Helper/FullScreenHelper.cs#L23-L59","documentation":"Validation guard at the entry of StartFullScreen: the window argument is null. The helper stores and mutates window state (styles, DWM transitions, monitor metrics) via Win32 interop, so a null reference must be rejected before any DependencyProperty or handle access. The message string is built with nameof(window) — 'window 不能为 null' means 'window cannot be null'.","triggerScenarios":"Thrown at src/Shared/HandyControl_Shared/Tools/Helper/FullScreenHelper.cs:41 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass a live, initialized Window instance to StartFullScreen/EndFullScreen — construct the window and ensure it is loaded before going full screen","Guard at the call site: 'if (window == null) return;' or log and skip when the window reference may be missing (e.g. during shutdown)","For APIs that can legitimately receive null, make the parameter nullable and treat null as a no-op instead of throwing"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"2c0875ebd67326e0c67282967e3e809c69282fee","analyzedAt":"2026-09-14T14:45:29.754Z","contentChangedAt":"2026-09-14T14:45:29.754Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}