Changing orientation of Xamarin iOS app does not show pop up in the center of the screen on screen rotation - xamarin.forms

I am using xamarin tool kit pop up in my xamarin app iOS. It works fine in portrait mode. If I change the orientation to landscape mode while the pop up is already opened , the pop up does not show in the centre of the screen. It shows on the left corner of the screen. It works well in android but in iOS it shows on left corner on screen rotation.
Below is my pop up code.
<?xml version="1.0" encoding="utf-8" ?>
<xct:Popup xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:xct="clr-namespace:Xamarin.CommunityToolkit.UI.Views;assembly=Xamarin.CommunityToolkit"
Size="360,200"
IsLightDismissEnabled="False"
x:Class="Mobile.NewPopup">
<StackLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" >
<Label Text="Sample PopUp"/>
</StackLayout>
</xct:Popup>
I am calling like this from the button click of my page.
await App.Current.MainPage.Navigation.ShowPopupAsync(new NewPopup();
In portrait mode it is opening in the center of the screen.
enter image description here
enter image description here
How can I move this the pop up tot he center of the screen while orientation change ?

Related

Status bar color is displaying at bottom of screen in xamarin forms iOS

In xamarin forms iOS, blue color is applying without providing any color at bottom.
This has to do with the ios Safe Area
If you have Page.SafeArea=True with a device with rounded corner, it will "truncate" a part. And show the Page.BackgroundColor behind (blue in your case)
If it's false, it will not truncate, but the content might be shown in an undesired way because of the rounded borders
I show you a Page with BackgroundColor="Red" and a StackLayout with BackgroundColor="Yellow"
On the right the page has Page.SafeArea="True" and on the left, with a False value

Image resizing inside a StackLayout in Xamarin.Forms

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="StackStuff.MainPage">
<StackLayout Orientation="Vertical">
<Image Source="image.jpg" VerticalOptions="Fill" HorizontalOptions="Fill"/>
</StackLayout>
</ContentPage>
I have a Xamarin.Forms project where I want an image to resize inside a StackLayout. I stripped it down to the minimal code above and if I resize the window, the image will only resize based off the window width. i.e. the image gets clipped off the bottom of the window if I change the height.
If I change the StackLayout's Orientation to Horizontal, I get the opposite - it'll resize based off a changing height, but not width.
If I completely remove the StackLayout and have only the image on the page, then the entire image will always be visible which is the behaviour I expected when it's inside the StackLayout.
Can anyone explain why this is? If I replace the Image with a BoxView, it'll happily resize and stay within the bounds of the StackLayout.
Thanks.
I solved this by wrapping the image in a grid:
<StackLayouenter code heret Orientation="Vertical">
<Grid>
<Image Source="image.jpg" VerticalOptions="Fill" HorizontalOptions="Fill"/>
</Grid>
</StackLayout>
I have no idea why it works but I guess that's Xamarin.Forms for you.

Draggable icon or image button in xamarin forms

I want to add draggable icon in mobile app which i can move anywhere on screen.
I tried with floating action but no luck.
<views:FloatingActionButton HorizontalOptions="End" VerticalOptions="End"
ImageSource="CallHistory.png"
x:Name="floCallHistory"
ButtonColor="Transparent"
Clicked="floCallHistory_Clicked" BackgroundColor="Transparent" FlowDirection="LeftToRight"
>
</views:FloatingActionButton>

Prevent toolbaritem icon center in iOS at Xamarin

I define a icon in Toolbaritems it show very good in Android on right but in iOS it show icon in ther Center of ther Navigation bar.
How I can put Icon on left same at Android.
Sorry for my poor English.
<ContentPage.ToolbarItems>
<ToolbarItem Text="Back" Order="Primary" IconImageSource="icon_delete_400.png" Clicked="OnBack" />
</ContentPage.ToolbarItems>
Android Show Right (Nice)
enter image description here
iOS show Center (Not good)
enter image description here
Github (Sample Source): https://github.com/westermost/Study-Xamarin
After running your project, I find the cause of your problem is the size of your image is too big(160*160) and it takes half area of the navigationBar, so it looks like stay in the center in your screenshot.
If you give a proper size of the image, it will show at the right side as your expected. I resize the image to 40* 40 and it works well.
Put toolbar item like this
<ContentPage.ToolbarItems>
<ToolbarItem Name="iconexample" Icon="icon_delete_400.png" Priority="0" Order="Primary" Clicked="OnBack" />
</ContentPage.ToolbarItems>
In ios place the image at /mipmap/icon_delete_400.png
In Android place the image at /mipmap/drawable/icon.png

How to create an overflow menu (not on the toolbar) - Xamarin.Forms

I understand how to create a ToolbarItem and set it's Order equal to Secondary which will give me an overflow menu like so:
But I'm not sure how I could implement such a menu in other parts of my application. For instance in the app I'm currently working on, I've removed the toolbar and created my own meaning there is no way to set the ToolbarItems property. I can add a ImageButton for the 3 dots overflow menu icon but I cannot get it to display a menu like the out of the box implementation does.
I'd also like to use this in other parts of my app (not just on the toolbar) such as on some sort of CardView.
Has anyone dealt with this problem before?
You can use Absolute layout to achieve this:
<AbsoluteLayout>
<StackLayout RowSpacing="0" AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All">
<!--Main Content of the screen-->
</StackLayout>
<BoxView Color="Gray" AbsoluteLayout.LayoutBounds="1,0,250,250" AbsoluteLayout.LayoutFlags="PositionProportional" />
</AbsoluteLayout>
In the above code I have used a BoxView of Gray background for that menu toolbar to just show a demo, you can implement your view and set the width and height accordingly and make that view visible on click of icon which you will add on the toolbar.
Output:
This can be easily achieved using AbsoluteLayout in Xamarin.Forms
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/layouts/absolute-layout
https://xamgirl.com/absolutelayout-in-xamarin-made-simple/

Resources