I'm trying to change my app's splash screen into a custom image, I haven't found a solution that solved it for me ... I will be more than happy if someone will be able to solve it.
Thanks
I'm using Xamarin iOS on Windows Visual Studio
You could consider adding a Page to your Forms project as a Splash Page.
like
public App()
{
InitializeComponent();
MainPage = new SplashPage();
}
Then add a delay in SplashPage to jump to MainPage.
public SplashPage()
{
InitializeComponent();
}
protected override void OnAppearing()
{
base.OnAppearing();
Task.Run(async ()=> {
await Task.Delay(3000);
Device.BeginInvokeOnMainThread(()=> { App.Current.MainPage = new MainPage();});
});
}
Related
I had build a Multipager Xamarin App, but after second page Android back button and Navigation back button is not working.
I had tried Shell Backbuttonbehavior , but with this only Top Navigation back button is working
<Shell.BackButtonBehavior>
<BackButtonBehavior Command="{Binding BackCommand}" IconOverride="back.png" />
</Shell.BackButtonBehavior>
I had tried overriding OnAppearing and OnDisappearing to set Current and pervious navigation but that too is not triggering on thrid page
protected override void OnAppearing()
{
base.OnAppearing();
Shell.Current.Navigating += Current_Navigating;
}
protected override void OnDisappearing()
{
base.OnDisappearing();
Shell.Current.Navigating -= Current_Navigating;
}
private async void Current_Navigating(object sender, ShellNavigatingEventArgs e)
{
if (Models.PatientPlannerData.moveNext == false)
{
Shell.Current.Navigating -= Current_Navigating;
await Shell.Current.GoToAsync("..", true);
}
}
For Navigation from one page to another I am using
await Shell.Current.GoToAsync(nameof(Page2));
Everything is working fine till second page, from third page back button is not triggering
For the Android back button, after compilation the Navigation Bar that we call in Xamarin Forms, turns into the Action Bar for Android during runtime.
Set the toolbar after LoadApplication(new App()); in OnCreate of MainActivity.
AndroidX.AppCompat.Widget.Toolbar toolbar
= this.FindViewById<AndroidX.AppCompat.Widget.Toolbar>(Resource.Id.toolbar);
SetSupportActionBar(toolbar);
And then overrode OnOptionsItemSelected(). When you press the backbutton on navigation bar, this event would be triggered.
public override bool OnOptionsItemSelected(IMenuItem item)
{
}
Ondisappearing() called soon after Onappearing() and onAppearing called right after onDisappearing. I had this issue only on one page. other pages do not have this issue. I found this when I tap on navbar back button, it does not navigate to the previous page, I had to tap twice to navigate back on this particular page..then I found this problem. degraded forms version 4.0 to 3.5 and recreated new page did not solve this issue..help need...
public Cart_Page2 ()
{
InitializeComponent ();
}
protected override void OnAppearing()
{
base.OnAppearing();
var vm = new Cart_page_vm();
vm.Navigation = Navigation;
BindingContext = vm;
}
protected override void OnDisappearing()
{
// MessagingCenter.Send<Cart_page>(this, "cart_page_disappear");
// Navigation.PopAsync();
}
In Xamarin Forms for iOS, I have a custom renderer for a ContentPage that displays a video control. In my Xamarin Forms app, this custom ContentPage is displayed inside a NavigationPage.
I would like to have the video screen open when a specific message comes in via MQTT.
When I open the video page by clicking a link on the main screen, it opens as expected. I know I am receiving the message via MQTT and calling Navigation.PushModalAsync() because of console statements and breakpoints. However, the custom rendered page is not displayed and the UI of my app freezes each time after calling PushModalAsync.
Is there something else I need to do to trigger Navigation.PushModalAsync() based on receiving an MQTT notification in the background of my app?
ViewRoomsPage.axml.cs:
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class ViewRoomsPage : ContentPage
{
public ViewRoomsPage()
{
InitializeComponent();
}
public string StreamUri { get; set; }
}
ViewRoomsPage.axml:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyForms.Pages.ViewRoomsPage">
<ContentPage.Content>
</ContentPage.Content>
VideoViewerRenderer.cs (video code removed; this should display a blank red screen. It also works when launched from a button on the main screen)
[assembly: ExportRenderer(typeof(ViewRoomsPage), typeof(ViewRoomsRenderer))]
namespace MyForms.IOS.NativeImplementations
{
public class ViewRoomsRenderer : PageRenderer
{
private IJKFFMoviePlayerController _playerController;
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
if (e.OldElement != null || Element == null)
{
return;
}
e.NewElement.BackgroundColor = Color.Red;
}
}
}
Method triggered from receiving an MQTT message
public void PushViewRooms()
{
Device.BeginInvokeOnMainThread(async () =>
{
await Application.Current.MainPage.Navigation.PushModalAsync(new ViewRoomsPage());
});
}
In App.xaml.cs:
public partial class App : Application
{
public App()
{
SetupDependencies(); // using StructureMap
Manager = DependencyContainer.Resolve<IMqttManager>();
Manager.Connect();
InitializeComponent();
var mainPage = new MainPage();
MainPage = new NavigationPage(mainPage);
}
}
The problem was a deadlock caused by a Task.WaitAll() being triggered in another section of code running in the background.
Thanks all who helped sanity check that it wasn't something in the way the renderer was set up.
I'd like to have a Xamarin PCL ContentPage that displays a welcome message and then loads data from a web service. I have the web service working but the problem is that in the following example nothing is displayed while it takes time to work.
What is the general strategy for: displaying a wait-type Splash page, waiting for a long-running task to complete, and then continuing with the rest of the application (say a Main Menu page)?
Hopefully the strategy will work in the PCL project so that I don't have to try and write iOS and Android versions? I've tried to put code in various override methods, but nothing seems to work. Thanks in advance for any advice.
// The following is called from the "App : Application" class.
public class SplashScreen : ContentPage
{
public SplashScreen()
{
Label lblWelcome = new Label { Text = "Hello. Please wait..." };
Content = new StackLayout
{
Children = { lblWelcome }
}
//TODO: Have the device display the above content before the following continues...
CallWebServiceToLoadParameters();
//TODO: Move on to display the Main Menu
}
}
This may do the trick:
public class SplashScreen : ContentPage
{
public SplashScreen()
{
Label lblWelcome = new Label { Text = "Hello. Please wait..." };
Content = new StackLayout
{
Children = { lblWelcome }
}
Device.BeginInvokeOnMainThread(async () => {
//If awaitable
var response = await CallWebServiceToLoadParameters();
if(response{
App.Current.MainPage = //Your main page.
}
});
}
}
A little bit ugly, the correct way will be with a ViewModel for each page.
I am not sure if it is just me, or everyone else out there, but every time i debug my Xamarin app on my mobile device i get a blank screen with an actionbar. The screen is displayed for about 2 seconds before it actually loads my specified screen.
Here is my PCL App.cs file:
public class App : Application
{
public App()
{
// The root page of your application
MainPage = new LogInPage();
}
protected override void OnStart()
{
// Handle when your app starts
}
protected override void OnSleep()
{
// Handle when your app sleeps
}
protected override void OnResume()
{
// Handle when your app resumes
}
}
The blank screen:
and then finally, after a few seconds:
What you are seeing is the default theme of the Activity being shown while Xamarin Forms is being initialized. You will tend to see this during a cold start. One way to work around it is to add a Splash Screen to show during initialization (Xamarin Android Splash Screen doc).