{"record":{"id":"17ddf160b497bdd8","repo":"dotnet/wpf","slug":"sr-flowdocumentreaderviewingmodeenabledconflict","errorCode":null,"errorMessage":"SR.FlowDocumentReaderViewingModeEnabledConflict","messagePattern":"SR\\.FlowDocumentReaderViewingModeEnabledConflict","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/FlowDocumentReader.cs","lineNumber":747,"sourceCode":"        /// <param name=\"viewingMode\">Viewing mode.</param>\n        protected virtual void OnSwitchViewingModeCommand(FlowDocumentReaderViewingMode viewingMode)\n        {\n            SwitchViewingModeCore(viewingMode);\n        }\n\n        /// <summary>\n        /// Called when IsInitialized is set to true.\n        /// </summary>\n        /// <param name=\"e\">Event arguments</param>\n        protected override void OnInitialized(EventArgs e)\n        {\n            base.OnInitialized(e);\n\n            // Defer the Is*ViewEnabled & ViewingMode conflict exception.\n            // Otherwise <FlowDocumentReader IsPageViewEnabled=\"false\" ViewingMode=\"TwoPage\"/> won't work.\n            if (IsInitialized && !CanSwitchToViewingMode(ViewingMode))\n            {\n                throw new ArgumentException(SR.FlowDocumentReaderViewingModeEnabledConflict);\n            }\n        }\n\n        protected override void OnDpiChanged(DpiScale oldDpiScaleInfo, DpiScale newDpiScaleInfo)\n        {\n            Document?.SetDpi(newDpiScaleInfo);\n        }\n\n        /// <summary>\n        /// Creates AutomationPeer (<see cref=\"UIElement.OnCreateAutomationPeer\"/>)\n        /// </summary>\n        protected override AutomationPeer OnCreateAutomationPeer()\n        {\n            return new FlowDocumentReaderAutomationPeer(this);\n        }\n\n        /// <summary>\n        /// An event reporting that the IsKeyboardFocusWithin property changed.","sourceCodeStart":729,"sourceCodeEnd":765,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/FlowDocumentReader.cs#L729-L765","documentation":"FlowDocumentReader.ViewingMode must be one of the views currently enabled via IsPageViewEnabled/IsTwoPageViewEnabled/IsScrollViewEnabled. The conflict check is deferred to OnInitialized (so XAML attribute order does not matter), but once initialized, if CanSwitchToViewingMode(ViewingMode) fails, ArgumentException (SR.FlowDocumentReaderViewingModeEnabledConflict) is thrown.","triggerScenarios":"Setting ViewingMode to Page/TwoPage/Scroll while the corresponding Is*ViewEnabled property is false (in XAML or code); runtime code disabling the active view's Is*ViewEnabled flag and forcing a re-check.","commonSituations":"XAML like <FlowDocumentReader IsPageViewEnabled=\"False\" ViewingMode=\"Page\"/>; data-bound ViewingMode whose value conflicts with enabled-view bindings; hiding views programmatically without changing ViewingMode.","solutions":["Set ViewingMode to a view that is enabled (check Is*ViewEnabled flags first)","Enable the desired view (set the matching Is*ViewEnabled=true) before/alongside setting ViewingMode","In code, guard: if (reader.CanSwitchToViewingMode(mode)) reader.ViewingMode = mode;"],"exampleFix":"// before\n<FlowDocumentReader IsScrollViewEnabled=\"False\" ViewingMode=\"Scroll\"/>\n// after\n<FlowDocumentReader IsScrollViewEnabled=\"True\" ViewingMode=\"Scroll\"/>","handlingStrategy":"validation","validationCode":"if (reader.CanSwitchToViewingMode(mode)) { reader.ViewingMode = mode; }","typeGuard":null,"tryCatchPattern":"try { reader.ViewingMode = mode; }\ncatch (ArgumentException) { /* requested view is disabled */ }","preventionTips":["Keep ViewingMode consistent with Is*ViewEnabled flags","Check CanSwitchToViewingMode before assigning in code","Verify XAML attribute combinations for ViewingMode and enabled flags"],"tags":["wpf","flowdocumentreader","conflict","argument-exception"],"backgroundTag":"conflicting-config-options","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}