Xamarin.Forms WPF PageRenderer Missing?

Created on 18 May 2018  ·  8Comments  ·  Source: xamarin/Xamarin.Forms

Description

I have a ContentPage in my Xamarin.Forms NetStandard Project and I am using a PageRenderer in my Xamarin.Forms platform specific projects. In Xamarin.Forms WPF I cannot find a PageRenderer to use.

Steps to Reproduce

  1. Setup a Xamarin.Forms Project
  2. Add a WPF project and set it up for Xamarin.Forms.
  3. Try to add a PageRender to the WPF Project

Expected Behavior

To be able to add a PageRenderer

Actual Behavior

Was not able to add PageRenderer

Basic Information

  • Version with issue: Xamarin Forms 3.1.0.469394-pre1
  • Last known good version: NA
  • IDE: VS 15.7.1
  • Platform Target Frameworks: WPF
  • Nuget Packages:
  • Affected Devices:

Screenshots

Reproduction Link

WPF needs-info ❓ needs-repro ❔

Most helpful comment

@mohachouch THANK YOU!!

That worked! I knew it had to be something simple. Spent 3 days trying to figure out if there was a way. You my friend are a life saver! Still don't know how you figured that out but glad you did!

All 8 comments

Are you using the 3.1 prerelease of the WPF nuget package? In what way are you unable to add a PageRenderer? It seems like I can use it in code as normal if I add all the proper packages and references. Can you upload a reproduction?

/cc @mohachouch

Thank you for the quick reply. I did not state the issue clearly enough, it is not being able to set its Content that is the issue.

Thanks for your response @pauldipietro ,

The problem I think is that there is no documentation on this stuff.
https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/custom-renderer/contentpage
That link does not cover Xamarin.WPF.

You can add a PageRenderer but how are you supposed to set its Content? If you get Element As ContentPage it is of type View, but in WPF it is a Page not a View, so how are you supposed to use the PageRenderer to display your WPF content? In UWP you do Children.Add(YourContent), in Android you do AddView(YourContent), but how do you accomplish this in WPF? Again, the following will not work bc one is a View and one is a Page.

page = new MyWPFPage(); ContentPage cpage = Element as ContentPage; cpage.Content = page;

The documentation is just so far behind that it is frustrating.

The rendering in WPF is different than the Android, iOS and UWP operation. All renderers inherit from ViewRenderer. This class has a generic property that corresponds to native control. To access the native component just do "this.Control".

You can see the source code of PageRenderer.cs and VisualPageRenderer.cs : https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Platform.WPF/Renderers/PageRenderer.cs

https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Platform.WPF/Renderers/VisualPageRenderer.cs

IK they are different but my point is "how do you use it in WPF"? I have read the source code already but it still appears it is expecting a View to be set. But in WPF it is a Page. this.Control is ReadOnly so I cannot set that to my WPF Page. Maybe I am just being stupid but I see no way to set this... I want to do something like below...

Inside the WPF PageRenderer inside OnElementChanged I do:
page = new MyWPFPage(); //My System.Windows.Controls.Page
this.Control = page; //How do I do this???

The Control property have a Content property. You can do this this.Control.Content = page; But you can’t use a page use à usercontrol.

@mohachouch THANK YOU!!

That worked! I knew it had to be something simple. Spent 3 days trying to figure out if there was a way. You my friend are a life saver! Still don't know how you figured that out but glad you did!

@wjvii if @mohachouch suggestions didn't solve your issue please let us know and we will reopen.

Was this page helpful?
0 / 5 - 0 ratings