How to Remove Navigation Bar Shadow and Line of content page in Xamarin.forms.
Is it possible to do this without rendering.
For just Xamarin Forms, iOS. Add this to your AppDelegate
UINavigationBar.Appearance.ShadowImage = new UIImage(); //No line under the navigation
Add this render class inside you xamarin ios project
[assembly: ExportRenderer(typeof(NavigationPage), typeof(CustomNavigationRenderer))]
namespace YOUR_IOS_NAMESPACE
{
public class CustomNavigationRenderer : NavigationRenderer
{
public override void ViewDidLoad()
{
base.ViewDidLoad();
NavigationBar.ShadowImage = new UIImage();
}
}
}
Related
Coming from UWP's development, i wondering is it is possible to have navigation inside a Frame in Xamarin Forms. I saw on documentation Frame element have INavigation property, so i tried this code :
MyFrame.Navigation.PushAsync(new Page1());
But when i'm trying to execute this code on Android, i get the following error :
System.InvalidOperationException: 'PushAsync is not supported globally
on Android, please use a NavigationPage.'
But when i do this :
public App()
{
InitializeComponent();
MainPage = new NavigationPage(new MainPage());
}
The navigation does not work as expected because it is global and not inside the Frame. We have to have a global navigation or it is impossible to have a specific navigation ? The goal is to have a static part in the app and a part where navigation takes place.
For example, with Uno Platform we can use UWP Frame and perform navigation inside it, so i wondering why it is not possible in Xamarin Forms.
We could define a property with type of INavigation in a custom Frame
public class MyFrame:Frame
{
public INavigation CurrentNavigation { get; private set; }
public MyFrame (INavigation navigation)
{
CurrentNavigation = navigation;
}
}
in MainPage
public MainPage()
{
InitializeComponent();
MyFrame myFrame = new MyFrame(this.Navigation);
myFrame.CurrentNavigation.PushAsync(new Page1());
}
I am trying to create a subclass of ImageButton called TintedImageButton that (surprise) can tint the image. I am following the basic structure of some TintedImage code I have found.
TintedImageButton has three renderers for iOS, Android and UWP.
The Android version of TintedImageButtonRenderer isn't working because it can't access the "Control" property of its superclass, ImageButtonRenderer. The Control should be the native widget.
I have been unable to locate the class documentation for ImageButtonRenderer but decompiling seems to indicate that the Control property has been made private for Android, but not for iOS. Does anyone know why this might be? How can I get the native widget so I can modify it?
The ImageButtonRenderer inherits from AppCompatImageButton, so the class myImageButtonRender itself is a native control which is a subclass of AppCompatImageButton.
[assembly: ExportRenderer(typeof(TintedImageButton), typeof(myImageButtonRender))]
namespace App261.Droid
{
class myImageButtonRender : ImageButtonRenderer
{
public myImageButtonRender(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.ImageButton> e)
{
base.OnElementChanged(e);
this.SetImageResource(Resource.Drawable.sample);
AppCompatImageButton imagV = this as AppCompatImageButton;
}
}
}
I have followed James Montemagno's guide on how to make a custom renderer for round images in my Xamarin Forms Shared Project.
https://blog.xamarin.com/elegant-circle-images-in-xamarin-forms/
(being a true copy of the guide it feels redundant to actually add the code itself to my project but please comment if that is not the case)
It is working flawless, however, I need to change the colour of the circle border dynamically with the press of a button when the app is running.
But since the colour of the circle is set natively in each renderer I am uncertain how I could possibly change it from my shared code.
Maybe this snippet can help:
public class CircleImage : Image
{
public static readonly BindableProperty CurvedBackgroundColorProperty =
BindableProperty.Create(
nameof(CurvedBackgroundColor),
typeof(Color),
typeof(CurvedCornersLabel),
Color.Default);
public Color CurvedBackgroundColor
{
get { return (Color)GetValue(CurvedBackgroundColorProperty); }
set { SetValue(CurvedBackgroundColorProperty, value); }
}
}
//Android/iOS
[assembly: ExportRenderer(typeof(CircleImage), typeof(CircleImageRenderer))]
namespace SchedulingTool.iOS.Renderers
{
public class CircleImageRenderer : ImageRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Image> e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
var xfViewReference = (CircleImage)Element;
//Here you can reference xfViewReference.CurvedBackgroundColor to assign what ever is binded.
}
}
}
}
I hope you get the main idea, you can create your own bindable properties and access them on the Native Renderer.
If everything does not go as expected you can always download the NuGet (which has everything you need):
https://github.com/jamesmontemagno/ImageCirclePlugin
How do I enable iOS 11 prefersLargeTitles throughout my Xamarin.Forms app?
I tried creating a custom renderer derived from PageRenderer for NavigationPage, setting:
ViewController.NavigationController.NavigationBar.PrefersLargeTitles = true;
This didn't have any effect, however.
Voila
[assembly: ExportRenderer(typeof(NavigationPage), typeof(NavBarRenderer))]
namespace LargeTitleSample.iOS
{
public class NavBarRenderer : NavigationRenderer
{
protected override void OnElementChanged(Xamarin.Forms.Platform.iOS.VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
NavigationBar.PrefersLargeTitles = true;
}
}
}
You have to create a custom renderer for the NavigationPage inheriting the NavigationRenderer. Then set the PrefersLargeTitles property on the NavigationBar to true.
It seems that when you add some scrollable control to the page, it will automatically have to 'big to small' effect when scrolling up, at least for a ListView.
Working example repo is here: https://github.com/jfversluis/LargeTitleSample
For XAML:
<NavigationPage Title="..." xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core" ios:NavigationPage.PrefersLargeTitles="true">
I'm using a ScrollView in Xamarin Forms and on iOS, the scrollview bounces (often too far) when you hit the top or the bottom. My understanding is this is default iOS behavior? Is there a way I can disable this so there is no bounce on scroll?
Yes, disabling the bouncing effect is possible. But you will need to create a Custom Renderer.
In your specific case, you have to use ScrollViewRenderer as a base class for your custom renderer. Then, in your custom renderer, you can simply set Bounces to false.
An example of a Custom Renderer can be found here. Your result should look something like this:
PCL:
public class CustomScrollView : ScrollView
{
public CustomScrollView() {}
}
iOS:
[assembly: ExportRenderer(typeof(CustomScrollView), typeof(CustomScrollViewRenderer))]
namespace Test.iOS
{
public class CustomScrollViewRenderer : ScrollViewRenderer
{
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
Bounces = false;
}
}
}
On Android, you will need to implement a Custom Renderer as well which simply does nothing.