I am using Xamarin.Forms 4.0 with a shell having a flyout at the left. I am trying to display an Image at the center of Shell.TitleView, however, I have no idea how to achieve this correctly. And the result is like what is suggest in the official page that the Image is not really at the center (but a bit at the right-hand side). This is probably because of the hamburger menu icon at the left, maybe(?)
I have tried to calculate the width of the hamburger menu icon after the view has been rendered and compensate at the margin of the Image, but since there is no page loaded event, at this moment I can only hard code a delay in the constructor of the ContentPage. But this is considered to be quite dirty and there will be a problem when there is an icon on the right-hand side.
public SomeContentPage()
{
InitializeComponent();
Device.StartTimer(new System.TimeSpan(0, 0, 0, 0, 500), () =>
{
var titleViewBound = Shell.GetTitleView(this).Bounds;
DisplayInfo displayInfo = DeviceDisplay.MainDisplayInfo;
double leftButtonWidth = displayInfo.Width / displayInfo.Density - titleViewBound.Width;
TitleImage.Margin = new Thickness(0, 0, leftButtonWidth, 0);
return false;
});
}
I expect there will be some better way to center an image in the TitleView no matter there is a hamburger menu icon or other icons at the right-hand side. Thanks in advance!
---Added sample for reference ---
I have white labelled the app and put it on Github for everyone reference. Thanks! Sample for reference: https://github.com/ltin071/XFShellFlyoutSample
The TitleImage is not at the center until pressing the adjust button underneath (which do the calculation mentioned above). I hope that I have missed some standard way to achieve that.