The type initializer for 'Xamarin.Forms.ItemsView' threw an exception. After click button.
Unhandled Exception:
System.TypeInitializationException: The type initializer for 'Xamarin.Forms.ItemsView' threw an exception. occurred
`<CarouselView>
<CarouselView.ItemsSource>
<x:Array Type="{x:Type View}">
<ContentView>
<Image Source="yuzon.jpg"/>
</ContentView>
<ContentView>
<Image Source="yuzyirmi.jpg"/>
</ContentView>
<ContentView>
<Image Source="yuzkirks.jpg" />
</ContentView>
<Image Source="yuzelli.jpg" />
<ContentView>
<Image Source="yuzaltmis.jpg" />
</ContentView>
<ContentView>
<Image Source="ikiyuzyirmi.jpg"/>
</ContentView>
<ContentView>
<Image Source="ikiyuzkirkC.jpg" />
</ContentView>
<ContentView>
<Image Source="ikiyuzyetmis.jpg" />
</ContentView>
<Image Source="ucyuz.jpg" />
<ContentView>
<Image Source="ucyuzF.jpg" />
</ContentView>
<ContentView>
<Image Source="ucyuzon.jpg" />
</ContentView>
<ContentView>
<Image Source="ucyuzotuz.jpg" />
</ContentView>
<ContentView>
<Image Source="ucyuzaltmis.jpg" />
</ContentView>
</x:Array>
</CarouselView.ItemsSource>
</CarouselView>`
This control belongs to Xamarin.Forms 4.0. So you have to update your forms version to 4.0 to test this new feature.
Moreover, you have to add
global::Xamarin.Forms.Forms.SetFlags("CollectionView_Experimental"); in your MainActivity.cs and AppDelegate to enable this testing.
Unfortunately, Carousel View can be only used on Android: https://github.com/pauldipietro/CollectionViewSample.
Follow this blog to learn more concepts: https://devblogs.microsoft.com/xamarin/xamarin-forms-4-0-feature-preview-an-entirely-new-point-of-collectionview/
Related
I am trying to make a frame a specific size but the frame seems to only match the size with components inside of the frame.
I tried finding solutions but couldn't find anything, perhaps I am searching for the wrong things.
The XAML:
<ScrollView>
<VerticalStackLayout
Spacing="25"
Padding="30,0"
VerticalOptions="Center">
<Frame BackgroundColor="#303030"
Padding="8" CornerRadius="5"
HeightRequest="500" WidthRequest="500">
<StackLayout Spacing="10">
<Label Text="Login" FontSize="Medium" FontAttributes="Bold" />
<BoxView Color="{DynamicResource Primary}" HeightRequest="2" HorizontalOptions="Fill" />
<Entry Placeholder="Username" />
<Entry Placeholder="Password" IsPassword="True" />
<Button Text="Login" BackgroundColor="{DynamicResource Primary}" TextColor="{DynamicResource White}" />
</StackLayout>
</Frame>
</VerticalStackLayout>
</ScrollView>
What it looks like:
What I want it to look like:
View toolmakersteve's response if you have this "issue" too!
Code:
<ScrollView>
<VerticalStackLayout
Spacing="25"
Padding="30,0"
VerticalOptions="Center"
WidthRequest="400"
HeightRequest="400">
<Border BackgroundColor="#303030"
Padding="8">
<StackLayout Spacing="10">
<Label Text="Login" FontSize="Medium" FontAttributes="Bold" />
<BoxView Color="{DynamicResource Primary}" HeightRequest="2" HorizontalOptions="Fill" />
<Entry Placeholder="Username" />
<Entry Placeholder="Password" IsPassword="True" />
<Button Text="Login" BackgroundColor="{DynamicResource Primary}" TextColor="{DynamicResource White}" Clicked="LoginClick" />
</StackLayout>
</Border>
</VerticalStackLayout>
</ScrollView>
Result:
In Xamarin Forms, having a XAML code: (an example below) is it possible to move the style of the Label and the Image to appplication level style and make it default for all Expander headers (or other containers)?
<xct:Expander>
<xct:Expander.Header>
<StackLayout>
<Label
Margin="20,10,0,10"
FontAttributes="Bold"
HorizontalOptions="StartAndExpand"
Text="ABCD"
TextTransform="Uppercase"
VerticalOptions="Center" />
<Image
Margin="0,0,20,0"
HorizontalOptions="End"
VerticalOptions="Center">
<Image.Source>
<FontImageSource
FontFamily="{StaticResource Font_FASolid}"
Glyph="{x:Static fonts:FASolid.ChevronDown}"
Size="{StaticResource MediumFontSize}" />
</Image.Source>
</Image>
</StackLayout>
</xct:Expander.Header>
</xct:Expander>
What I would like to have in my xaml finally is just:
<xct:Expander>
<xct:Expander.Header>
<StackLayout>
<Label Text="ABCD"/>
<Image>
<Image.Source>
<FontImageSource/>
</Image.Source>
</Image>
</StackLayout>
</xct:Expander.Header></xct:Expander>
I'm developing a Xamaring.Forms cross-platform app, and want to show Loading gif when user click a button to connect to the server. Everythink is working as expected except the gif image is not shown, even when I try with a different format of images I also don't see any images.
I have Installed all the required packages of ffimageloading and the gif image locate in project root ,drawable folder of android project and Resources folder of IOS project.
I gave the property of Embedded Resource to the image in Android project.
I'm using Android emulator to test the Android project.
I'm using Xamarin Live Player to test the IOS project
Hier is my code:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:ff="clr-namespace:FFImageLoading.Forms;assembly=FFImageLoading.Forms"
xmlns:ffSvg="clr-namespace:FFImageLoading.Svg.Forms;assembly=FFImageLoading.Svg.Forms"
xmlns:ffTransformations="clr-namespace:FFImageLoading.Transformations;assembly=FFImageLoading.Transformations"
x:Class="MyApp.Login"
Title="Login"
NavigationPage.HasNavigationBar="False">
<ContentPage.Padding>
<OnPlatform x:TypeArguments="Thickness" iOS="0, 20, 0, 0"/>
</ContentPage.Padding>
<ContentPage.Content>
<AbsoluteLayout BackgroundColor="White">
<StackLayout VerticalOptions="StartAndExpand" AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All">
<Image Source="Logo.png" Aspect="AspectFit"/>
<StackLayout Padding="30, 10, 30, 0">
<Label x:Name="errormessage" TextColor="Red"/>
<Entry x:Name="EmailEntry" Placeholder="Email" Keyboard="Email" Margin="0, 10"/>
<Entry x:Name="PasswordEntry" IsPassword="true" Placeholder="Password" />
<Entry x:Name="CompanyEntry" Placeholder="Company" />
<Button x:Name="LoginBtn" Pressed="Pressed_Handler" Text="Login" Clicked="Login_Handler" BackgroundColor="Black" TextColor="White" FontAttributes="Bold" Margin="90, 30" />
</StackLayout>
</StackLayout>
<StackLayout x:Name="LoadingView" AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All" BackgroundColor="Black" Opacity="0.3">
</StackLayout>
<StackLayout x:Name="LoadingView2" AbsoluteLayout.LayoutBounds="0.5,0.5,200,200" AbsoluteLayout.LayoutFlags="PositionProportional" BackgroundColor="Black">
<Label Text="Loading..." TextColor="White" FontAttributes="Bold" FontSize="30" VerticalOptions="Center"/>
<!-- ------------- here is the gif image ----------------- -->
<ff:CachedImage x:Name="Gif" Source="resource://MyApp.LoadingGif.gif" />
</StackLayout>
</AbsoluteLayout>
</ContentPage.Content>
This is not how resource:// should be used. It is used to share the same file inside common dll. You're using it as a platform specific file, change:
Source="resource://MyApp.LoadingGif.gif" to Source="LoadingGif.gif"
I'm currently working in a new ContentPage for my application and I have some controls with DataTemplates.
I would like to use a Command in my ContentPage's ViewModel in one of the DataTemplates, however I'm not sure how to do the right reference for this to work properly. Here's my XAML code:
<?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="MaverickMobileOnline.ImagesListingPage"
--MANY NAMESPACE REFERENCES--
>
<ContentPage.Resources>
<ResourceDictionary>
<c:ItemTappedEventArgsConverter x:Key="ItemTappedConverter" />
<c:ItemAppearingEventArgsConverter x:Key="ItemAppearingConverter" />
<c:BooleanNegationConverter x:Key="not" />
</ResourceDictionary>
</ContentPage.Resources>
<StackLayout Spacing="0">
<commonViews:MainCustomNavBar MinimumHeightRequest="120" />
<controls:PullToRefreshLayout
x:Name = "layout"
RefreshCommand="{Binding btn_reload_businesses_images_click}"
IsEnabled = "True"
IsRefreshing="{Binding Path=is_businesses_loading}" >
<ScrollView
x:Name = "scrollView"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<templates:ItemsStack
Padding="0"
Margin="0,10,0,10"
x:Name="itmStack"
BackgroundColor="White"
ItemsSource="{Binding Path=photos_list}">
<templates:ItemsStack.ItemTemplate>
<DataTemplate>
<artina:GridOptionsView
Padding="10,0"
ColumnSpacing="10"
RowSpacing="10"
VerticalOptions="Fill"
HeightRequest="120"
ColumnCount="3"
RowCount="1"
ItemsSource="{Binding Path=.}">
<artina:GridOptionsView.ItemTemplate>
<DataTemplate>
<ContentView
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MaverickMobileOnline.GalleryImageItemTemplate"
xmlns:ffimageloading="clr-namespace:FFImageLoading.Forms;assembly=FFImageLoading.Forms"
xmlns:fftransformations="clr-namespace:FFImageLoading.Transformations;assembly=FFImageLoading.Transformations">
<ContentView.Content>
<ffimageloading:CachedImage
FadeAnimationEnabled="true"
Aspect="AspectFill"
VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand"
LoadingPlaceholder="advertising_photo_placeholder.png"
Source="{Binding Path=image_medium}" />
</ContentView.Content>
<ContentView.GestureRecognizers>
<TapGestureRecognizer
-- HERE! --
Command="{Binding Source={x:Reference X}, Path=BindingContext.command_name}"
CommandParameter="{Binding image_medium}"
/>
</ContentView.GestureRecognizers>
</ContentView>
</DataTemplate>
</artina:GridOptionsView.ItemTemplate>
</artina:GridOptionsView>
</DataTemplate>
</templates:ItemsStack.ItemTemplate>
</templates:ItemsStack>
</ScrollView>
</controls:PullToRefreshLayout>
</StackLayout>
</ContentPage>
Please take a look at the code after the mark "-- HERE! --".
PS: I'm just refining this layout on order to improve performance.
Any help will be appreciated.
UPDATE:
ViewModel:
public RelayCommand<string> btn_image_tap_preview
{
get
{
return new RelayCommand<string>(
OpenImagePreview
);
}
}
//* Image tap
private async void OpenImagePreview(string url)
{
//* Some code
}
Updated XAML:
<StackLayout x:Name="mainStack" Spacing="0">
<commonViews:MainCustomNavBar MinimumHeightRequest="120" />
....
<ContentView.GestureRecognizers>
<TapGestureRecognizer Command="{Binding Source={x:Reference mainStack}, Path=BindingContext.btn_image_tap_preview}"
CommandParameter="{Binding image_medium}" />
</ContentView.GestureRecognizers>
I'm debugging but I can't reach the ViewModel's command.
You can use x:Reference and take the binding context of any layout or element from your content page like StackLayout. Since its binding context is the ViewModel of the page it would have the command you are looking for at the first level itself. You can directly use it.
<StackLayout x:Name="myStackLayout" Spacing="0">
<commonViews:MainCustomNavBar MinimumHeightRequest="120" />
....
<ContentView.GestureRecognizers>
<TapGestureRecognizer Command="{Binding Source={x:Reference myStackLayout}, Path=BindingContext.command_name}"
CommandParameter="image_medium" />
</ContentView.GestureRecognizers>
Or you can set the binding context for TapGesture
<TapGestureRecognizer BindingContext="{Binding Source={x:Reference myStackLayout.BindingContext}}" Command="{Binding command_name}"
DataTemplates does not seem to work well with x:Reference prior to v1.4.4, you can read more about in the forum post - x:Reference not working?.
The implementation in the newer version can be seen in the answer here.
If you are interested the Bugzilla issue that was fixed is here.
I am new to Xamarin.Forms in which I need loading message. How can I display the loading message?
Code:
<AbsoluteLayout>
<StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" AbsoluteLayout.LayoutBounds="0, 0, 1, 1"
AbsoluteLayout.LayoutFlags="All" Padding="30" >
<Grid>
//something
</Grid>
</StackLayout>
<ContentView x:Name="overlay" AbsoluteLayout.LayoutBounds="0, 0, 1, 1" AbsoluteLayout.LayoutFlags="All" IsVisible="False" BackgroundColor="#C0808080" Padding="10, 0">
<ActivityIndicator WidthRequest="110" HeightRequest="70" IsRunning="True" IsVisible="True" Color="Black" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"/>
</ContentView>
</AbsoluteLayout>
Set IsVisible="True" for ContentView will show you the ActivityIndicator.
<ContentView x:Name="overlay" AbsoluteLayout.LayoutBounds="0, 0, 1, 1" AbsoluteLayout.LayoutFlags="All" IsVisible="True" BackgroundColor="#C0808080" Padding="10, 0">
<ActivityIndicator WidthRequest="110" HeightRequest="70" IsRunning="True" IsVisible="True" Color="Black" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"/>
</ContentView>
If you are using MVVM and want full modal Loading Messages look at ACR User Dialogs for Xamarin and Windows. You can install it via nuget. You can find the sample application here.