A part of tabbedPage is sheltered in IOS - xamarin.forms

Just a simple project of maui,it use tabbar shell
------AppShell-----
<Shell
x:Class="TABSample.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:TABSample"
Shell.FlyoutBehavior="Disabled">
<TabBar>
<Tab Title="Test">
<ShellContent Title="Test1" ContentTemplate="{DataTemplate local:NewPage1}" />
<ShellContent Title="Test2" ContentTemplate="{DataTemplate local:NewPage2}" />
</Tab>
</TabBar>
</Shell>
-----NewPage1---------------
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TABSample.NewPage1"
Title="NewPage1">
<StackLayout>
<Label
Text="Welcome to .NET MAUI!"
VerticalOptions="Center"
HorizontalOptions="Center" />
</StackLayout>
</ContentPage>
-----------Iphone 14 pro IOS 16.2------------------
enter image description here
cannot see the label text
----------Android--------------------------
enter image description here
A part of tabbedPage is sheltered in IOS, the reason is iOS Simulator? Screen content is only shown in a part of screen in iOS Simulator
but ohter page is ok

Yes I could reproduce your issue. Just as #Bas H mentioned, the control is behind the tabs. I also found the same issue in Github: Contentpage is cut off in iOS #8778. You could follow it.
For a workaround, you could set the page padding
protected override void OnAppearing()
{
base.OnAppearing();
Padding = new Thickness(0, 40, 0, 0);
}
or set like #Bas H suggested but i think use Margin is better:
<VerticalStackLayout Margin="{x:OnPlatform iOS='0,40,0,0', Android='0'}" >

Related

Keyboard flashes when navigating in Shell flyouts

My Xamarin.Forms app is using Shell flyouts for navigation. When I navigate the app on iOS, I notice a strange behaviour. Reproduction steps:
Go to a page that has an Entry in it
Type anything into the Entry
Go to another page
Return to the same page you typed something into the Entry
The keyboard then pops up and then disappears right after. I can see the cursor in the Entry appear then disappear too. I removed a lot of my code to try to find the problem, but I can not find it. My code:
AppShell.xaml:
<Shell xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MyApp.Views"
Title="MyApp"
x:Name="shellAppShell"
x:Class="MyApp.AppShell">
<FlyoutItem x:Name="flyoutItemMainPage" Title="Home" Icon="icon_about.png">
<ShellContent x:Name="shellContentMainPage" Route="MainPage" ContentTemplate="{DataTemplate local:MainPage}" />
</FlyoutItem>
<FlyoutItem x:Name="flyoutItemAPage" Title="A Page" Icon="Pagea.png">
<ShellContent x:Name="shellContentPageA" Route="PageA" ContentTemplate="{DataTemplate local:PageA}" />
</FlyoutItem>
<!-- More flyouts... -->
</Shell>
PageA.xaml:
<ContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Name="PageA"
x:Class="MyApp.Views.PageA">
<ContentPage.Content>
<StackLayout Orientation="Vertical" >
<Entry />
<Button Text="back" Clicked="OnBackClicked"/>
</StackLayout>
</ContentPage.Content>
</ContentPage>
PageA.xaml.cs
public partial class PageA : ContentPage
{
public PageA()
{
InitializeComponent();
}
void OnBackClicked(object sender, EventArgs e)
{
Shell.Current.CurrentItem = AppShellGlobal.ShellContentMainPage;
}
}
After my testing, this situation only occurs in iOS.
There is a simpler solution, you can rewrite the ContentPage and end the editing state of the page when the page loads.
First, create the MyPageRenderer class in your project's xxx.iOS directory.
Here is the internal code:
[assembly: ExportRenderer(typeof(ContentPage), typeof(MyPageRenderer))]
namespace App15.iOS
{
public class MyPageRenderer : PageRenderer
{
public override void ViewDidAppear(bool animated)
{
View.EndEditing(true);//Solved the problem with this line of code
base.ViewDidAppear(animated);
}
}
}
Here is the screenshot:

Disable iOS autocomplete in Xamarin.Forms SearchBar

I have a Xamarin.Forms SearchBar to search for information on a remote server. This data is displayed in a ListView below the searchbar like the following:
Pseudocode:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage ... >
<ContentPage.Content>
<StackLayout>
<SearchBar
x:Name="SearchBar"
Placeholder="Search for a business..."
HorizontalTextAlignment="Start"
SearchCommand="{Binding PerformSearch}"
SearchCommandParameter="{Binding Text, Source={x:Reference SearchBar}}">
</SearchBar>
<ListView
x:Name="SearchResults"
ItemsSource="{Binding Path=SearchResults}"
...
>
</ListView>
</StackLayout>
</ContentPage.Content>
</ContentPage>
Is it possible to disable the autocomplete/autocorrect in the keyboard? I know for a Text.Entry it is possible to set IsTextPredictionEnabled to false but I don't see a way to configure a SearchBar in a similar way.
Yes, according to the SearchBar Properties, the Keyboard for the InputView is exposed. Therefore, similar to this answer, it can be achieved in the XAML by using the x:FactoryMethod attribute:
<SearchBar
x:Name="SearchBar"
Placeholder="Search for a business..."
HorizontalTextAlignment="Start"
SearchCommand="{Binding PerformSearch}"
SearchCommandParameter="{Binding Text, Source={x:Reference SearchBar}}">
<SearchBar.Keyboard>
<Keyboard x:FactoryMethod="Create">
<x:Arguments>
<KeyboardFlags>None</KeyboardFlags>
</x:Arguments>
</Keyboard>
</SearchBar.Keyboard>
</SearchBar>

(Xamarin.Forms) Shell does not work with TabbedPage in IOS

I'm using Shell with buttom nav and want to be able to have one of the tabs as a TabbedPage. Also one of my contentpages in Shell have a toolbar item which leads to a tabbedpage, this also does not work in iOS, but both working fine in Android.
What I mean by not working is that even though I set the background color to white, I just get a black "blank-screen", I see nothing.
I tried to create a new TabbedPage, same issue, tryed the newest 3.6 forms release and also the 4.0 beta 9pre release, still same issue.
Update
Here is my tabbedpage:
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyApp.Page.TabbedPageTest"
BackgroundColor="White">
<!--Pages can be added as references or inline-->
<ContentPage Title="Tab 1" BackgroundColor="White">
<Label Text="Label in tab 1" TextColor="Orange" />
</ContentPage>
<ContentPage Title="Tab 2" BackgroundColor="White">
<Label Text="Label in tab 2" TextColor="Orange" />
</ContentPage>
<ContentPage Title="Tab 3" BackgroundColor="White">
<Label Text="Label in tab 3" TextColor="Orange" />
</ContentPage>
</TabbedPage>
Here is where I load it:
<ShellItem>
<ShellSection Title="PageOne" Icon="ic_action_myicon1.png">
<ShellContent ContentTemplate="{DataTemplate local:MyListView}" />
</ShellSection>
<ShellSection Title="PageTwo" Icon="ic_action_myicon2.png">
<ShellContent ContentTemplate="{DataTemplate local:MyContentPage}" />
</ShellSection>
<ShellSection Title="PageThree" Icon="ic_action_myicon3.png">
<ShellContent ContentTemplate="{DataTemplate local:TabbedPageTest}"/>
</ShellSection>
</ShellItem>
The listview and contentPage works fine. The TabbedPage are just black from top to buttom.

Xamarin.Forms: How to hide the Navigation Bar Separator on iOS devices?

I have changed the default color of the navigation bar by using these codes in app.xaml as I am unable to make it transparent on iOS devices:
<Style TargetType="NavigationPage">
<Setter Property="BarBackgroundColor" Value="#0a82b8" />
<Setter Property="BarTextColor" Value="#ffffff" />
</Style>
Now, there is an unnecessary navigation bar separator on iOS:
On Microsoft's official website, it says these codes can be helpful:
This platform-specific hides the separator line and shadow that is at
the bottom of the navigation bar on a NavigationPage. It's consumed in
XAML by setting the NavigationPage.HideNavigationBarSeparator bindable
property to false:
<NavigationPage ...
xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
ios:NavigationPage.HideNavigationBarSeparator="true">
</NavigationPage>
Alternatively, it can be consumed from C# using the fluent API:
using Xamarin.Forms.PlatformConfiguration;
using Xamarin.Forms.PlatformConfiguration.iOSSpecific;
public class iOSTitleViewNavigationPageCS : Xamarin.Forms.NavigationPage
{
public iOSTitleViewNavigationPageCS()
{
On<iOS>().SetHideNavigationBarSeparator(true);
}
}
Source: Hiding the Navigation Bar Separator on a NavigationPage
The problem is that when I want to paste the ios:NavigationPage.HideNavigationBarSeparator="true" property into the <NavigationPage>tag, it gives this error:
No property, bindable property, or event found for 'HideNavigationBarSeparator', or mismatching type between value and property.
My full codes are:
<?xml version="1.0" encoding="utf-8"?>
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:My.App" x:Class="My.App.MainPage">
<MasterDetailPage.Master>
<ContentPage Title="Menu" BackgroundColor="#0a82b8" Icon="menu.png">
<StackLayout Orientation="Vertical">
<ListView x:Name="navigationDrawerList" RowHeight="55" SeparatorVisibility="None" BackgroundColor="#ffffff" ItemSelected="OnMenuItemSelected">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<!-- Main design for our menu items -->
<StackLayout VerticalOptions="FillAndExpand" Orientation="Horizontal" Padding="20,10,0,10" Spacing="20">
<Label Text="{Binding Title}" FontSize="Large" VerticalOptions="Start" HorizontalOptions="CenterAndExpand" TextColor="#28DDFF" FontAttributes="Bold" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage>
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<NavigationPage xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
ios:NavigationPage.HideNavigationBarSeparator="true">
</NavigationPage>
</MasterDetailPage.Detail>
</MasterDetailPage>
Here is the tutorial which I followed for the MasterDetail navigation. The file which has <NavigationPage> tag is named as MainPage.xaml
You can use a custom renderer to hide that shadow:
[assembly: ExportRenderer(typeof(NavigationPage), typeof(CustomNavigationPage))]
namespace CustomNavigationPage.iOS
{
public class CustomNavigationPage : NavigationRenderer
{
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
NavigationBar.SetBackgroundImage(new UIKit.UIImage(), UIKit.UIBarMetrics.Default);
NavigationBar.ShadowImage = new UIKit.UIImage();
}
}
}
While you have accepted the answer, this one is more precise - you haven't followed the instructions that you have pasted from the site as you have ommited this line:
xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
Place UINavigationBar.Appearance.ShadowImage = new UIImage(); inside the public override bool FinishedLaunching(UIApplication app, NSDictionary options) method within AppDelegate.cs file. AppDelegate.cs resides within the iOS project of Xamarin.Forms

how to set icon for Toolbar Item in Xamarin forms

My xamarin andorid project does not have Drawawble folders under Resources, I have mipmap folders instead. I'm trying to set icon for a toolbar item in shared project. If I set an image as embeded resource I should be able to access it from the shared project, am I wrong?
<?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="BoringAppUi.MainPage" Title="Main Page">
<ContentPage.ToolbarItems>
<ToolbarItem Text="Logout" Clicked="OnLogoutButtonClicked" Order="Primary" Priority="0"/>
<ToolbarItem Text="Home" Icon="#mipmap/baseline_home_blue_48.png" Clicked="OnHomeIconClicked" Order="Primary" Priority="1"/>
</ContentPage.ToolbarItems>
<ContentPage.Content>
<StackLayout>
<Label Text="Main app content goes here" HorizontalOptions="Center" VerticalOptions="CenterAndExpand" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
Also I've tried setting it from the code behind
var toolbarItemHome = new ToolbarItem
{
Text = "Home",
Icon = "#mipmap/baseline_home_blue_48.png"
};
toolbarItemHome.Clicked += OnHomeIconClicked;
ToolbarItems.Add(toolbarItemHome);
From c# code:
new ToolbarItem () { Icon = "icon.png"}
Or from xaml:
<ToolbarItem Name="iconexample" Icon="icon.png" Priority="0" Order="Primary" Activated="Onclick" />
Have that in mind:
iOS - place the image at /mipmap/icon.png
Android - place the image at /mipmap/drawable/icon.png

Resources