dotnet/wpf · error · ArgumentException

SR.FlowDocumentReaderViewingModeEnabledConflict

Error message

SR.FlowDocumentReaderViewingModeEnabledConflict

What it means

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.

Solutions

  1. Set ViewingMode to a view that is enabled (check Is*ViewEnabled flags first)
  2. Enable the desired view (set the matching Is*ViewEnabled=true) before/alongside setting ViewingMode
  3. In code, guard: if (reader.CanSwitchToViewingMode(mode)) reader.ViewingMode = mode;

Example fix

// before
<FlowDocumentReader IsScrollViewEnabled="False" ViewingMode="Scroll"/>
// after
<FlowDocumentReader IsScrollViewEnabled="True" ViewingMode="Scroll"/>
Defensive patterns

Strategy: validation

Validate before calling

if (reader.CanSwitchToViewingMode(mode)) { reader.ViewingMode = mode; }

Try / catch

try { reader.ViewingMode = mode; }
catch (ArgumentException) { /* requested view is disabled */ }

Prevention

When it happens

Trigger: 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.

Common situations: XAML like <FlowDocumentReader IsPageViewEnabled="False" ViewingMode="Page"/>; data-bound ViewingMode whose value conflicts with enabled-view bindings; hiding views programmatically without changing ViewingMode.

Understand the failure class

Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/17ddf160b497bdd8. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/FlowDocumentReader.cs:747

        /// <param name="viewingMode">Viewing mode.</param>
        protected virtual void OnSwitchViewingModeCommand(FlowDocumentReaderViewingMode viewingMode)
        {
            SwitchViewingModeCore(viewingMode);
        }

        /// <summary>
        /// Called when IsInitialized is set to true.
        /// </summary>
        /// <param name="e">Event arguments</param>
        protected override void OnInitialized(EventArgs e)
        {
            base.OnInitialized(e);

            // Defer the Is*ViewEnabled & ViewingMode conflict exception.
            // Otherwise <FlowDocumentReader IsPageViewEnabled="false" ViewingMode="TwoPage"/> won't work.
            if (IsInitialized && !CanSwitchToViewingMode(ViewingMode))
            {
                throw new ArgumentException(SR.FlowDocumentReaderViewingModeEnabledConflict);
            }
        }

        protected override void OnDpiChanged(DpiScale oldDpiScaleInfo, DpiScale newDpiScaleInfo)
        {
            Document?.SetDpi(newDpiScaleInfo);
        }

        /// <summary>
        /// Creates AutomationPeer (<see cref="UIElement.OnCreateAutomationPeer"/>)
        /// </summary>
        protected override AutomationPeer OnCreateAutomationPeer()
        {
            return new FlowDocumentReaderAutomationPeer(this);
        }

        /// <summary>
        /// An event reporting that the IsKeyboardFocusWithin property changed.

View on GitHub (pinned to 81131a70a4)