How to turn layers on programatically in the PDFViewWPF viewer using C# .NET 4.0

I have followed the documentation and examples:
1) I can dump layers out to BMP - nice but not what I need
2) I can see and access all my layers by cycling through the Optional Content Groups.

What I can't do and is an absolute must is to be able to turn on a layer of my choosing in the viewer. I have tried to set the states on the config context, tried setting current and initial state on each OC group. And of course with each of my attempts I, at the end, update the PDFViewWPF viewer to reset to the document and to Update the Page Layout.

All I get is still just the initial drawing with no layers turned on. I also saw mention of a layers panel with the viewer, yet I can not find how to turn this on either.

Hello John,

You should be able to call Current_View.SetOCGContext() within PDFViewControl.xaml.cs. Please let me know if this is not working for you.

That worked! Thank you very much!!

Hi, It does not work for me.
How did you refresh the viewer?
Can you please post a sample code to show how to do that?


After calling SetOCGContext, you will want to call Update method to refresh the viewer.

Along with the PDFNet SDK for .Net there is also the regular PDFViewCtrl class, and samples, and these samples include a layers ui from which you can turn on/off layers. If you are having problems you may want to try the sample and verify exactly what each OCG layer is doing for the particular file(s) you are using.

Thanks, it is now working for me.
what I did is as follows, the order before might have been wrong:

Config init_cfg = doc.GetOCGConfig();

Context ctx = new Context(init_cfg);

ctx.SetState(group, state);