How to use xamarin form xaml page in xamarin.ios

SureshM.4402SureshM.4402 INMember ✭✭

Hi is it possible to use xamarin form xaml page in xamarin.ios project. I all ready created xamarin native xamarin.ios project now i want to use xaml page.

Answers

  • ColeXColeX Member, Xamarin Team Xamurai
    edited January 7

    is it possible to use xamarin form xaml page in xamarin.ios project.

    Yes, create a xaml page , and use the method CreateViewController , you can convert it to native ViewController.

    [Register("AppDelegate")]
    public class AppDelegate : UIApplicationDelegate
    {
        public static AppDelegate Instance;
    
        UIWindow _window;
        UINavigationController _navigation;
    
        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            Forms.Init();
    
            Instance = this;
            _window = new UIWindow(UIScreen.MainScreen.Bounds);
    
            UINavigationBar.Appearance.SetTitleTextAttributes(new UITextAttributes
            {
                TextColor = UIColor.Black
            });
    
            var mainPage = new PhonewordPage().CreateViewController();
            mainPage.Title = "Phoneword";
    
            _navigation = new UINavigationController(mainPage);
            _window.RootViewController = _navigation;
            _window.MakeKeyAndVisible();
    
            return true;
        }
        ...
    }
    

    Refer https://docs.microsoft.com/en-us/xamarin/xamarin-forms/platform/native-forms#ios

  • SureshM.4402SureshM.4402 INMember ✭✭

    Hi Thank you for your response. I already have story board views. now i need to load xaml page in one button click event.

  • ColeXColeX Member, Xamarin Team Xamurai
    edited January 7
    1. Add the Xamarin.Forms NuGet package to the native project.

    2. Add the following code in the button click event.

      var mainPage = new YourPage().CreateViewController();
      this.PresentViewController(mainPage, true, null);
      
Sign In or Register to comment.