Gorilla-Player-Support icon indicating copy to clipboard operation
Gorilla-Player-Support copied to clipboard

Doesn't recognise classes derived from ContentPage/ContentView

Open CliffCawley opened this issue 8 years ago • 3 comments

I've overridden the ContentPage to create BaseContentPage as I have some generic error handling, styling, advanced page lifetime and message subscription that I use.

I get:

XAML preview is currently only supported for Xamarin Forms Pages and ContentViews. ViewJobDetails.xaml was not recognized as a page/view (root XAML tag is BaseContentPage), thus no preview will be rendered.
public class BaseContentPage : ContentPage, IPageLifetime

If it's possible, it would be great if you could inspect BaseContentPage and realise that it's derived from ContentPage and still render the page. The code class doesn't affect the appearance at all, it's just some additional tooling.

CliffCawley avatar May 11 '16 21:05 CliffCawley

I was happy to see the release notes "Gorilla 0.9.1.2 adds support for derived pages" however now when I load my xaml it says in Gorilla Preview

Error loading XAML. The reported error: System.TypeLoadException: Cound not load type Xamarin.Forms.BaseContentPage

CliffCawley avatar Jun 14 '16 01:06 CliffCawley

Hi Cliff,

In order to preview XAML that includes derived pages you must use the Gorilla SDK. The documentation on how to do this is on its way.

There is a new sample, distributed with the installer, that shows how to use derived pages. You can locate it by clicking the Gorilla tray icon and selecting "Show Player and Samples location". The sample is under the HowTo directory.

The key points to take a look in the samples are:

  • Integrate the SDK in your solution. This is done by adding the SDK Nuget packages to your platform specific projects (Droid and iOS). Please, manually remove the previous SDK (0.8.3) if you already have it in your solution.
  • Configure Gorilla.json file. This file tells Gorilla which assemblies should be considered valid. Invalid/unknown assemblies found in the XAML will be removed by Gorilla by default.
  • Load Gorilla instead of your application. Take a look at MainActivity and AppDelegate in the sample to see how this is done.
LoadApplication(UXDivers.Gorilla.iOS.Player.CreateApplication(
       new UXDivers.Gorilla.Config("Good Gorilla")
            .RegisterAssembliesFromTypes<ViewModelBase, WelcomePage>()));
  • Finally you will need to register the known assemblies in the Config object instantiated in the MainActivity and AppDelegate. Currently we need you to reregister your known assemblies here. Sorry for that, we will avoid this double registration in the future. This registration can be done using out RegisterAssembly \ RegisterAssemblies or RegisterAssemblyFromType \ RegisterAssembliesFromType methods of the Config object. In the former you pass the assemblies as parameters. In the latter you just pass types that are within the assembly you want to register and Gorilla will get the container assembly for you.
  • (optional) You add a new project Configuration to your solution so you can easily switch between Gorilla mode and you app. The DerivedPages solution has an example of this.

Please notice that we do not support having an abstract class as the root tag of the XAML.

Hope it helps.

LeoHere avatar Jun 14 '16 09:06 LeoHere

Hi as I understand in the last version of Gorilla you have some changing in this solution. So what is the best solution now?

viccotr avatar Dec 26 '17 15:12 viccotr