Going from the carousel page to the carousel view - xamarin

I read the following message on the page: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/navigation/carousel-page
The CarouselPage has been superseded by the CarouselView, which
provides a scrollable layout where users can swipe to move through a
collection of items. For more information about the CarouselView, see
Xamarin.Forms CarouselView.
In this regard, I decided to start using the CarouselView.
But when I tried to use the carousel to look out for the page carousel and got an error: the ElementTemplateContent property was set more than once.
<CarouselView xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:local="clr-namespace:test.Views"
x:Class="test.Corusel">
<CarouselView.ItemTemplate>
<DataTemplate>
<local:Page1></local:Page1>
<local:Page2></local:Page2>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
Here is the result I want to get.
<CarouselPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:local="clr-namespace:test.Views"
x:Class="test.Corusel">
<CarouselPage.Children>
<local:Page1></local:Page1>
<local:Page2></local:Page2>
</CarouselPage.Children>
I wanted to use the carousel view because I need indicators.

Your DataTemplate contains 2 child elements. Remove one and it will work.
There can be only be 1 template content inside DataTemplate.
If you want to use both,you can add both pages in any single layout like StackLayout,ContentView,ContentPage etc:
<CarouselView xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:local="clr-namespace:test.Views"
x:Class="test.Corusel">
<CarouselView.ItemTemplate>
<DataTemplate>
<StackLayout>
<local:Page1></local:Page1>
<local:Page2></local:Page2>
</StackLayout>
</DataTemplate>
</CarouselView.ItemTemplate>
Or
you can merge both pages code into a single page

You can use DataTemplateSelector if you need different templates for different items: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/carouselview/populate-data#choose-item-appearance-at-runtime

Related

Xamarin forms Prism Content Page Design

I'm working on Xamarin Project and I don't need navigation bur, I switched it off but now I cant move app content of page
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:prism="http://prismlibrary.com"
prism:ViewModelLocator.AutowireViewModel="True"
xmlns:imgExt="clr-namespace:GulfStar.Xamarin.Extensions"
x:Class="GulfStar.Xamarin.Views.StatusPickerPage"
NavigationPage.HasNavigationBar="False">
<StackLayout>
<StackLayout Orientation="Horizontal" VerticalOptions="Start" >
<Image Source="{imgExt:ImageResource GulfStar.Xamarin.Images.Icon.png}" WidthRequest="70" HeightRequest="70"/>
<Label HorizontalOptions="Center" Margin="0,17,0,0" FontSize="Title">GSI Accountability</Label>
</StackLayout>
</StackLayout>
</ContentPage>
I figured out who it happen
How to remove blue section
Use NavigationPage.SetHasNavigationBar(this, false); to hide the navigation bar.
I figured out how to make that thing disappears
when you navigation to some page does not use Navigation page NavigationService.NavigateAsync("NavigationPage/StatusPickerPage");
Use
NavigationService.NavigateAsync("StatusPickerPage");
And it would not track navigation and its not needed if you have only two pages

How in CarouselPage to divide ContentPage into different files?

In one xaml file I have a carousel. Starting from the second section, the code for the next page is also listed here. For compactness I would like to make as partial applications in asp.net. Is it possible to split the Contentpage into different files for each page for greater convenience? Thanks !
<CarouselPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design">
<ContentPage
BackgroundImage="background">
<ContentPage.Content>
<StackLayout>
<Image
Source="logo">
</Image>
<Frame>
<local:SearchProfile
Keyboard="Default">
</local:SearchProfile>
</Frame>
<Image
Source="starttext">
</Image>
</StackLayout>
</ContentPage.Content>
</ContentPage>
<ContentPage>
<ContentPage.Content>
<StackLayout>
<Image Source="map"></Image>
</StackLayout>
</ContentPage.Content>
</ContentPage>
You can’t have multiple pages in one page. You can only have multiple layouts inside a page.
The CarouselPage can’t have a ContentPage inside it and vice versa. However the CarouselPage can have multiple layouts in it (Stack, Relative, Absolute, Frame, Grid)
Here's a quick snippet explaining Pages vs Layouts.

How to add Search bar in top of a tabbed page in xamarin forms

In my xamarin app,I want to add a search bar on top of the page in my tabbed page.
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Sample.Mobile.Test">
<StackLayout>
<SearchBar></SearchBar>
</StackLayout>
<TabbedPage.Children>
<ContentPage x:Name="tab1" Title="Home">
</ContentPage>
</TabbedPage.Children>
</TabbedPage>
You can use follow this link for the Search bar Implementation
https://developer.xamarin.com/api/type/Xamarin.Forms.SearchBar/

Do I need to surround a <TableView> with a <StackLayout> in a <ContentPage>

I am working on an application where the developer has a <ContentPage> with a <TableView> inside. Is this needed / normal practice? I am trying to work out why the developer did this.
The developer added a element surrounding the <TableView>
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
Title="Network">
<ContentPage.Content>
<StackLayout>
<TableView>
...
</TableView>
</StackLayout>
</ContentPage.Content>
</ContentPage>
A ContentPage can only have a single child element. It's not uncommon to include some sort of Layout container as the child, so multiple child elements can be added to the page. However, in cases like this where there is really only a single child it's probably unnecessary.

Xamarin CarouselPage not showing if not master page

I've inherited a Xamarin project and am not sure why I'm seeing this behavior when trying to work with a CarouselPage.
Using the Prism NavigationService, if I navigate to the carousel page as the "base page", it shows fine, but if I navigate to it as a "sub page" (to push it on the navigation stack?) it doesn't show, though I get no errors.
The problem is that using the navigation method that works doesn't provide me with a back button.
Example:
// this works, but no back button
await _navigationService.NavigateAsync("file:///MenuMasterDetailPage/MenuNavigationPage/MyCarouselPage");
// this doesn't, have back button but no content is shown
await _navigationService.NavigateAsync("MyCarouselPage");
I'm unsure how the master/detail/navigation stuff really works: not sure if my issue is there or if there's something special about a CarouselPage that prevents it from being rendered in the second case.
The MyCarouselPage is as simple as can be while I try to get this to work:
<?xml version="1.0" encoding="utf-8" ?>
<CarouselPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
x:Class="Views.ImageCarouselPage"
effects:BackgroundImageEffect.BackgroundImage="Resources.SignInBackground.png">
<ContentPage>
<StackLayout VerticalOptions="FillAndExpand">
<Image Source="https://s3.amazonaws.com/blah.jpg" Aspect="AspectFit" VerticalOptions="FillAndExpand" />
</StackLayout>
</ContentPage>
<ContentPage>
<StackLayout VerticalOptions="FillAndExpand">
<Image Source="https://s3.amazonaws.com/blah.jpg" Aspect="AspectFit" VerticalOptions="FillAndExpand" />
</StackLayout>
</ContentPage>
</CarouselPage>
(I should note that the background image does display, but the contents of the carousel does not).
Any ideas? Thanks.

Resources