CarouselView not working in Xamarin.Forms - xamarin.forms

I would like to use CarouselView , I have installed it already (CarouselView.FormsPlugin) and I checked the packeges.config of my project and it is already there :
but still I am getting this error
The type or namespace name 'CarouselView' could not be found in the global namespace (are you missing an assembly reference?)
how can I fix this problem?

It looks like you're not using the official CarouselView. In the case of the CarouselView.FormsPlugin, the name is a CarouselViewControl.
Try it like this:
<controls:CarouselViewControl x:Name="myView">
<controls:CarouselViewControl.ItemTemplate>
<DataTemplate>
<Label Text="{Binding .}" HorizontalOptions="Center" VerticalOptions="Center"/>
</DataTemplate>
</controls:CarouselViewControl.ItemTemplate>
</controls:CarouselViewControl>

<?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:local="clr-namespace:XamlTest"
xmlns:controls="clr-namespace:CarouselView.FormsPlugin.Abstractions;assembly=CarouselView.FormsPlugin.Abstractions"
x:Class="XamlTest.MainPage">
<controls:CarouselView x:Name="myView">
<controls:CarouselView.ItemTemplate>
<DataTemplate>
<Label Text="{Binding .}" HorizontalOptions="Center" VerticalOptions="Center"/>
</DataTemplate>
</controls:CarouselView.ItemTemplate>
</controls:CarouselView>
</ContentPage>

Could you show your code in XAML?
Maybe you forgot to put the assembly / namespace?
If so try to put this in your content page tag:
xmlns:carousel="clr-namespace:CarouselView.Forms.Plugin;assembly=CarouselView.Forms.Plugin"
When you do that you can call the control with :

In my case, I had the wrong namespace in the XAML inside <ContentPage> tag. This is correct:
xmlns:controls="clr-namespace:CarouselView.FormsPlugin.Abstractions;assembly=CarouselView.FormsPlugin.Abstractions"

Related

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>

Can I create some small views including created views to use it in mainPage?

Can I create a view including Entry Progress bar or others to make a view which I can use in other places?
for example I want to create a card view which I can use to list the lists.
I can only write in the list not to write the card in every list.
Yes, you can create a custom view and use it in the MainPage or other Pages, Views you want.
To create a custom view, add a new item --> ContentView,let's call it CardView:
In .cs of CardView:
public partial class CardView : ContentView
{
public CardView()
{
InitializeComponent();
}
}
In xaml of CardView, add your labels,progressbar, entry there:
<?xml version="1.0" encoding="UTF-8"?>
<ContentView 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"
x:Class="App35.CardView">
<ContentView.Content>
<StackLayout>
<Label Text="Hello Xamarin.Forms!" />
<ProgressBar Progress="0.5" />
<Entry Placeholder="I'm entry"/>
</StackLayout>
</ContentView.Content>
</ContentView>
To use it in MainPage, in listView or in the page:
<StackLayout>
<projectName:CardView HorizontalOptions="Center" VerticalOptions="CenterAndExpand" />
<ListView x:Name="listView" RowHeight="70">
<ListView.ItemsSource>
<x:Array Type="{x:Type x:String}">
<x:String>mono</x:String>
<x:String>monodroid</x:String>
</x:Array>
</ListView.ItemsSource>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<projectName:CardView HorizontalOptions="Center" VerticalOptions="CenterAndExpand" />
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
I upload a sample here and you can check.
Yes you can do that using ContentView, if you want to use it as views
Or you can make ViewCells if you want to use it in ListViews. Its easy and almost every project does that.
You can refer this link :- https://xamarinhelp.com/xamarin-forms-user-control/
Let me know if you have more questions on this. Thanks!

xamarin.forms add switch in toolbar

Is it possible to add a switch on the toolbar?
<ContentPage.ToolbarItems>
<ToolbarItem>
<Switch x:Name="Switch1" IsToggled="True" Margin="5,0,0,0"/>
</ToolbarItem>
</ContentPage.ToolbarItems>
Does anybody have any ideas?
Thanks!
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:TitleViewSample"
x:Class="TitleViewSample.MainPage">
<NavigationPage.TitleView>
<Switch x:Name="Switch1" IsToggled="True" Margin="5,0,0,0"/>
</NavigationPage.TitleView>
<ContentPage.Content>
<StackLayout>
<!-- Place new controls here -->
<Label Text="Welcome to Xamarin.Forms!"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
I don't think it is possible. You can, however, take the same approach I did when I needed to customise my title bar.
First, you hide the navigation bar, then you can specify your bar at the top, and use the controls you would like.

Why do I get a build warning "button is assigned but its value is never used" in the Xamarin.Forms hello world example?

I'm following the hello xamarin quickstart project https://developer.xamarin.com/guides/xamarin-forms/getting-started/hello-xamarin-forms/quickstart/ for Xamarin.Forms and I'm getting a warning The private field Phoneword.MainPage.translateButon is assigned but its value is never used in the generated code files
/Demo/Phoneword/obj/Debug/Phoneword.MainPage.xaml.g.cs(46,46): Warning CS0414: The private field `Phoneword.MainPage.translateButon' is assigned but its value is never used (CS0414) (Phoneword)
Here's the XAML
<?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="XamDemo.MainPage">
<ContentPage.Padding>
<OnPlatform x:TypeArguments="Thickness" iOS="20, 40, 20, 20" Android="20, 20, 20, 20" WinPhone="20, 20, 20, 20" />
</ContentPage.Padding>
<ContentPage.Content>
<StackLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Orientation="Vertical" Spacing="15">
<Label Text="Enter a Phoneword:" />
<Entry x:Name="phoneNumberText" Text="1-855-XAMARIN" />
<Button x:Name="translateButon" Text="Translate" Clicked="OnTranslate" />
<Button x:Name="callButton" Text="Call" IsEnabled="false" Clicked="OnCall" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
Why am I getting that warning? The project seems to work fine and the translate button does call a method so it is being used. I don't get the same warning for callButton which seems like it was declared in the same way. What's going on?
A translateButon field is generated in the Phoneword.MainPage.xaml.g.cs file because of the x:Name="translateButon" attribute.
This attribute gives you access to the Button element if you wanted to do anything with it in the MainPage.cs code file.
But all you need to do is done in the Xaml, namely what action should happen on click. So the warning will disappear if you remove the x:Name="translateButon" attribute.

Xamarin.Forms How do we remove a child from a TabbedPage's children?

I would like to add and remove child pages from a tabbed page in certain conditions.
However, it gives me that collection "Children" is read only .
Has anyone succeeded ?
Here is the code for TabbedPage
<TabbedPage 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"
xmlns:partialViews="clr-namespace:TestTabbed.Views.PartialViews;assembly=TestTabbed"
prism:ViewModelLocator.AutowireViewModel="False"
x:Class="TestTabbed.Views.MainPage"
ItemsSource="{Binding ChannelLists}" Appearing="MainPage_OnAppearing"
Disappearing="MainPage_OnDisappearing">
<TabbedPage.ItemTemplate>
<DataTemplate>
<ContentPage Title="{Binding Name}" x:Name="mainContentPage">
<ContentPage.Content>
<OnIdiom x:TypeArguments="View">
<OnIdiom.Phone>
<partialViews:MainPhoneView />
</OnIdiom.Phone>
<OnIdiom.Tablet>
<partialViews:MainTabletView />
</OnIdiom.Tablet>
</OnIdiom>
</ContentPage.Content>
</ContentPage>
</DataTemplate>
</TabbedPage.ItemTemplate>
</TabbedPage>
Seeing your code might be helpful in case I am missing the actual issue but the following should work for you (note that you cannot directly assign a collection to the TabbedPage.Children property which is what it sounds like you are running into):
TabbedPage tab = new TabbedPage();
ContentPage page = new ContentPage();
tab.Children.Add(page);
tab.Children.Remove(page);
Where as the following will not work:
TabbedPage tab = new TabbedPage();
tab.Children = new List<Page>();

Resources