dotnet/wpf · error
Only one DocumentPageView with IsMasterPage property set to…
Error message
Only one DocumentPageView with IsMasterPage property set to True allowed.
What it means
Among the DocumentPageView objects in a DocumentViewerBase's PageViews collection, exactly one at most may have the attached property IsMasterPage set to true; it designates the master page used for zooming and layout. VerifyDocumentPageViews throws ArgumentException if two or more views declare IsMasterPage=true.
Solutions
- Ensure only one DocumentPageView has IsMasterPage="True"
- Remove the IsMasterPage attribute from duplicated views or set it to False
- Set IsMasterPage programmatically after building the collection, guarding so only the first view gets it
Example fix
// before <vw:DocumentPageView IsMasterPage="True"/> <vw:DocumentPageView IsMasterPage="True"/> // after <vw:DocumentPageView IsMasterPage="True"/> <vw:DocumentPageView/>
Defensive patterns
Strategy: validation
Validate before calling
int masters = pageViews.Cast<DocumentPageView>().Count(pv => DocumentViewerBase.GetIsMasterPage(pv));
if (masters > 1) { /* unset IsMasterPage on all but the first */ } Try / catch
try { viewer.PageViews = pageViews; }
catch (ArgumentException ex) when (ex.Message.Contains("IsMasterPage")) { /* fix master page flags */ } Prevention
- Mark exactly one view as master (or none)
- When duplicating DocumentPageView elements in XAML, strip IsMasterPage from copies
- Compute the master flag programmatically after composing the list
When it happens
Trigger: Setting IsMasterPage=true on two or more DocumentPageView instances in the same PageViews collection (in XAML or code) before assigning it to the viewer.
Common situations: Copying a DocumentPageView element in XAML (including its IsMasterPage attribute) to create multiple pages, forgetting to reset IsMasterPage on the copies.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Cannot have empty collection of DocumentPageView objects.
- Bracket characters cannot be alpha-numeric or whitespace.
- Bracket characters cannot be one of the following: '=' …
- DocumentViewer element can have only one child.
- InvalidDrawingAttributesWidth
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/f1ed3f812a9e0c83.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DocumentViewerBase.cs:874
private void VerifyDocumentPageViews(ReadOnlyCollection<DocumentPageView> pageViews)
{
int index;
bool hasMasterPage = false;
// At least one DocumentPageView is required.
if (pageViews == null)
{
throw new ArgumentException(SR.DocumentViewerPageViewsCollectionEmpty);
}
// Expecting only one DocumentPageView with IsMasterPage property set to true.
for (index = 0; index < pageViews.Count; index++)
{
if (GetIsMasterPage(pageViews[index]))
{
if (hasMasterPage)
{
throw new ArgumentException(SR.DocumentViewerOneMasterPage);
}
hasMasterPage = true;
}
}
// Unique PageNumbers for each active DocumentPageView.
}
/// <summary>
/// Does deep Visual tree walk to retrieve all DocumentPageViews.
/// It stops recursing down into visual tree in following situations:
/// a) Visual is UIElement and it is not part of Contol Template,
/// b) Visual is DocumentPageView.
/// </summary>
/// <param name="root">FrameworkElement that is part of Control Template.</param>
/// <param name="pageViews">Collection of DocumentPageViews; found elements are appended here.</param>
/// <returns>Whether collection of DocumentPageViews has been updated.</returns>
private void FindDocumentPageViews(Visual root, List<DocumentPageView> pageViews)View on GitHub (pinned to 81131a70a4)