Forum Xamarin Xamarin.Forms

Overwriting Content Page: Issues with xaml.g.cs-files

Mo719Mo719 Member ✭✭

Hi guys,

so I created an OrientationContentPage class inheriting from ContentPage, which implements a functions and an event handler to let me react to changes of the screen orientation (Credits @NMackay).
See here

My pages now inherit from that OrientationContentPage class.
I get the error "Partial declarations of "MainPage" (one of my pages) must not specify different base classes".
I fixed this error by also changing the inheritance in the MainPage.xaml.g.cs:

public partial class MainPage : global::Xamarin.Forms.OrientationContentPage {

    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Forms.Build.Tasks.XamlG", "")]
    private global::Xamarin.Forms.ToolbarItem NextWeek;

    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Forms.Build.Tasks.XamlG", "")]
    private void InitializeComponent() {
        global::Xamarin.Forms.Xaml.Extensions.LoadFromXaml(this, typeof(MainPage));
        NextWeek = global::Xamarin.Forms.NameScopeExtensions.FindByName<global::Xamarin.Forms.ToolbarItem>(this, "NextWeek");

but unfortunatly, VS is changing it back to "public partial class MainPage : global::Xamarin.Forms.ContentPage" all the time.
Is there a better way to do what I want to do (throwing an event when rotating the phone)?

Also, is there a way to get the startup orientation of the phone?

Thanks a lot for helping :)

Sign In or Register to comment.