I'm trying to move a Button
in the NavigationBar from the right side to the left in a custom page renderer in Android. CropDetailPage
is a content page in the shared code.
[assembly: ExportRenderer(typeof(CropDetailPage),typeof(CropDetailPageRenderer))]
namespace MyApp.Droid
{
public class CropDetailPageRenderer : PageRenderer
{
public CropDetailPageRenderer(Context context)
: base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
{
base.OnElementChanged(e);
if (e.OldElement != null || Element == null)
{
return;
}
var bar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
bar.SetBackgroundColor(Android.Graphics.Color.Azure);
// Only have 1 child
bar.GetChildAt(0).SetX(10);
}
}
}
I'm getting this exception when I try to open the refered page
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
I've tried commenting the code inside my OnElementChanged
method, but the exception keeps happening, so I know it's not coming from the logic.
Also, is this the right way to customize the appearance of a Toolbar
? Since I wanted to move my button to the left, I just thought of changing the X coordinate
.
Any ideas to what's happening ?
Edit: Xaml for button
<ContentPage.ToolbarItems>
<ToolbarItem Text="Back" Command="{Binding GoBackCommand}"></ToolbarItem>
</ContentPage.ToolbarItems>
<ContentPage.Content>
....
</ContentPage.Content>