WPF DocumentViewer doesn't display images

Yannick Lalbatry 21 Reputation points
2022-12-22T14:09:23.933+00:00

I have an XPS file, originaly created from WPF with 2 controls, one TextBox and one Image.
I can open the XPS file in the Windows Viewer without problem.

When running this code, the image is not displayed, what is wrong?

public partial class MainWindow : Window  
{  
    public MainWindow()  
    {  
        InitializeComponent();  
  
        var xps = new XpsDocument("printPreview.xps", FileAccess.Read);  
        viewer.Document = xps.GetFixedDocumentSequence();  
  
        xps.Close();  
    }  
}  

<Window x:Class="XpsTest.MainWindow"  
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"  
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"  
    xmlns:local="clr-namespace:XpsTest"  
    mc:Ignorable="d"  
    Title="MainWindow" Height="450" Width="800">  
    <Grid>  
        <DocumentViewer Name="viewer"/>  
    </Grid>  
</Window>  

Git:
https://github.com/yannicklal/XpsTest

Developer technologies XAML
{count} votes

Accepted answer
  1. Castorix31 90,521 Reputation points
    2022-12-27T12:23:40.7+00:00
    1 person found this answer helpful.

5 additional answers

Sort by: Most helpful
  1. fdelvalle 1 Reputation point
    2022-12-28T17:17:31.76+00:00

    Thank you, it works for me too, but the command you wrote has a typo:

    reg add "HKLM\SOFTWARE\Microsoft.NET\Framework\Windows Presentation Foundation\XPSAllowedTypes" /v "DisableDec2022Patch" /t REG_SZ /d "*" /reg:64  
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.