Prism Forms - can not see NavigationBar - xamarin.forms

Xamarin.Forms: 3.0.0.550
Prism: 7.0.0.396
Here is my code snippet in App.xaml.cs :
protected override void OnInitialized()
{
InitializeComponent();
NavigationService.NavigateAsync("NavigationPage/CoursesPage");
}
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterForNavigation<NavigationPage>();
containerRegistry.RegisterForNavigation<CoursesPage>();
containerRegistry.RegisterForNavigation<MainPage>();
containerRegistry.RegisterForNavigation<Content>();
}
After running I do not see NavigationBar on CoursesPage even if is set NavigationPage.HasBackButton="True" in xaml file.
Any idea what can be wrong?

Related

Android flash image

I try to flash an image view for 3 seconds and then return it to its original image. here is my code:
public class MainActivity extends AppCompatActivity
implements View.OnClickListener{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.imageView).setOnClickListener(this);
}
#Override
public void onClick(View v) {
ImageView pic = findViewById(R.id.imageView);
pic.setImageDrawable(getResources().getDrawable(R.drawable.devil));
//Wait Block
try
{
Thread.sleep(3000);
} catch (InterruptedException e){
Toast.makeText(this,"Problem occurred",Toast.LENGTH_LONG).show();
}
//End of wait block
pic.setImageResource(R.drawable.angel);
Toast.makeText(this,"Done",Toast.LENGTH_LONG).show();
}
So basically I want this code flow:
While the actual flow is the following :
Could you tell me the reason for this behavior as well as how to solve this?

Xamarin.Forms : Need to go back to previous page on back button press even if entry has focus

If my entry field has focus and i click on hardware back button, the entry field looses focus but i am not able to navigate to previous page. I have to hit the back button again. I know this is the expected behaviour, but i need to navigate to the previous page on the first back button press itself. Need some help regarding this.
This behavior is by design.But you could use custom renderer and custom a EditText to achieve the effect.
1.create a CustomEntry :
public partial class CustomEntry:Entry
{
public static readonly BindableProperty BackPressProperty=BindableProperty.Create("BackPress", typeof(EventHandler), typeof(CustomEntry), null);
public event EventHandler BackPress;
public void OnBack()
{
EventHandler eventHandler = this.BackPress;
eventHandler?.Invoke((object)this, EventArgs.Empty);
}
}
2.create a custom EditText MyEditText in your Android project:
class MyEditText: FormsEditText
{
public MyEditText(Context context) : base(context)
{
}
public override bool OnKeyPreIme([GeneratedEnum] Keycode keyCode, KeyEvent e)
{
if (keyCode == Keycode.Back)
{
if (listener != null)
{
listener.onKeyBack();
return true;
}
}
return base.OnKeyPreIme(keyCode, e);
}
private OnEditTextKeyBackListener listener;
public void setOnEditTextKeyBackListener(OnEditTextKeyBackListener listener)
{
this.listener = listener;
}
public interface OnEditTextKeyBackListener
{
void onKeyBack();
}
}
3.custom EntryRenderer MyEntryRenderer:
[assembly: ExportRenderer(typeof(CustomEntry), typeof(MyEntryRenderer))]
namespace EntryCa.Droid
{
class MyEntryRenderer:EntryRenderer,OnEditTextKeyBackListener
{
private Context context;
private EditText editText;
public MyEntryRenderer(Context context) : base(context)
{
this.context = context;
}
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
MyEditText editText = new MyEditText(context);
editText.setOnEditTextKeyBackListener(this);
editText.SetSingleLine(true); //this and below line to set done key
editText.ImeOptions = ImeAction.Done;
SetNativeControl(editText);
}
public void onKeyBack()
{
hideSoftInput();
((CustomEntry)Element).OnBack();
}
InputMethodManager mInputMethodManager = (InputMethodManager)Android.App.Application.Context.GetSystemService(Context.InputMethodService);
public void hideSoftInput()
{
if (mInputMethodManager != null)
{
mInputMethodManager.HideSoftInputFromWindow(WindowToken, HideSoftInputFlags.NotAlways);
}
}
}
}
4.use in your page.xaml:
<local:CustomEntry HorizontalOptions="StartAndExpand" WidthRequest="200" BackPress="CustomEntry_BackPress"></local:CustomEntry>
in your page.xaml.cs:
private void CustomEntry_BackPress(object sender, EventArgs e)
{
Navigation.PopAsync();
}

Xamarin Forms MapRenderer OnMapReady event equivalent for iOS?

I need an equivalent event for an iOS renderer:
public class MyMapRenderer : Xamarin.Forms.Maps.Android.MapRenderer
{
...
protected override void OnMapReady(GoogleMap map)
{
base.OnMapReady(map);
// need to do things here
}
...
}
Thanks
You can use MKMapViewDelegate_MapLoaded to handle your actions in iOS renderer:
public class CustomMapRenderer : MapRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<View> e)
{
base.OnElementChanged(e);
var nativeMap = Control as MKMapView;
nativeMap.MapLoaded += NativeMap_MapLoaded;
}
private void NativeMap_MapLoaded(object sender, EventArgs e)
{
Console.WriteLine("NativeMap_MapLoaded");
}
}

My scroll view does not responding i can not scroll down

In my XAML file, I used scroll view for scroll down but it does not work I can not find any issue where I did a couple of extra things here one is I add pull to refresh nuget and use it and I create a theme content class and I inherited it with default content page. another command in content page is working but scroll view does not support
Here my Xaml file
<views:BaseContentPage.Content>
<ScrollView BackgroundColor="White">
<controls:PullToRefreshLayout x:Name="PullToRefreshLayout" IsPullToRefreshEnabled="True" RefreshCommand="RefreshPatientDetailsPage">
<StackLayout>
// some code
</StackLayout>
</controls:PullToRefreshLayout>
</ScrollView>
</views:BaseContentPage.Content>
this is the Base content page I create
public abstract class BaseContentPage : ContentPage
{
public readonly BaseViewModel BaseViewModel;
protected bool IsNavigated;
public BaseContentPage(BaseViewModel baseViewModel)
{
BaseViewModel = baseViewModel;
}
protected abstract override void OnAppearing();
protected override void OnDisappearing()
{
IsNavigated = true;
}
}
I think this scroll view does not work because of the NuGet I put or it's the base content page
for android, I used this customer render
public class SortPaneListViewRendererAndroid : ListViewRenderer
{
public SortPaneListViewRendererAndroid(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.VerticalScrollBarEnabled = false;
var listView = Control as Android.Widget.ListView;
listView.DividerHeight = 1;
}
}
}
The reason this was happening is because you are nesting scrollable controls, Removing one of them will solve the issue

Splash screen prism xamarin.forms

I would like to create a splash screen in my xamarin.forms application which is using the prism.autofac.forms nuget package. Basically I want to create the same splash screen for each platform. Currently my Android application looks like this
[Activity(Label = "MyApp", Theme = "#style/MyTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
ToolbarResource = Resource.Layout.Toolbar;
TabLayoutResource = Resource.Layout.Tabbar;
base.OnCreate(bundle);
Forms.Init(this, bundle);
LoadApplication(new Application(new DroidInitializer()));
}
}
and the application looks like this:
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Application : PrismApplication
{
public Application(IPlatformInitializer initializer) : base(initializer)
{
NavigationService.NavigateHomeAsync();
}
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterForNavigation<NavigationPage>("Navigation");
containerRegistry.RegisterForNavigation<MainPage>("Index");
containerRegistry.RegisterForNavigation<HomePage>();
}
protected override void OnInitialized()
{
InitializeComponent();
}
}
Where should I implement and show the splash screen? I want to NavigateHome when all registering are finished.
Splash screens should be implemented in the platform projects.
For iOS the recommended solution is to use a storyboard for it, https://learn.microsoft.com/en-us/xamarin/ios/app-fundamentals/images-icons/launch-screens?tabs=vsmac
For Android I use to create a theme for the splash screen, https://learn.microsoft.com/en-us/xamarin/android/user-interface/splash-screen
You can make them look the same, but you have to do it on each platform.

Resources