Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all 76418 articles
Browse latest View live

VS2019 and iOS - ItemView broken?

$
0
0

Anyone else seeing something similar?
VS2019 windows - Xamarin Forms App - Runs fine on Android

Same app when run to iOS breaks on the ListView and CollectionView

If I take out all three, it runs fine.

If I take out the CollectionView only - it breaks
If I take out both of the ListView - it breaks
Sure seems like the common class they derive from (ItemView) has a problem on iOS only.

Thoughts? - Again, runs fine in Android

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
    x:Class="RpxSkeleton.MainPage"
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:RpxSkeleton"
    x:Name="this"
    BackgroundColor="{Binding App.CurrentTheme.WindowBackground}"
    ControlTemplate="{StaticResource PageTemplateDefault}">
    <ScrollView Orientation="Vertical" VerticalScrollBarVisibility="Always">
        <StackLayout Orientation="Vertical">

            <Label
                BackgroundColor="{Binding App.CurrentTheme.LabelBackground}"
                FontSize="20"
                HorizontalOptions="Center"
                Text="RedPillXamarin.com™"
                TextColor="{Binding App.CurrentTheme.LabelForegound}"
                VerticalOptions="Center" />

            <Grid>
                <StackLayout>
                    <Button
                        x:Name="Test"
                        Clicked="Test_OnClicked"
                        Text="Test" />
                </StackLayout>
            </Grid>

            <Button Command="{Binding ToggleIsBusyCommand}" Text="Toggle IsBusy" />


            <ListView
                BackgroundColor="Blue"
                IsEnabled="True"
                ItemsSource="{Binding WidgetCollection}">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <StackLayout Orientation="Horizontal">
                                <Switch IsToggled="{Binding IsSelected}" />
                                <Entry BackgroundColor="Lime" Text="{Binding Name}" />
                                <DatePicker BackgroundColor="SaddleBrown" Date="{Binding SomeDate}" />

                                <!--  UI layer even for UI purposes. Not for logic or workflow  -->
                                <!--  Notice that it is automatically wired to the page code behind without having to specify it  -->
                                <Button Clicked="Button_OnClicked" Text="UI Layer" />

                                <!--  The ListView binded collection element has the command and the handler  -->
                                <Button Command="{Binding ModelCommand}" Text="Model Command" />

                                <!--  The command is on the ViewModel and takes the collection element as the parameter  -->
                                <Button
                                    Command="{Binding Source={x:Reference this}, Path=BindingContext.VmCommand}"
                                    CommandParameter="{Binding .}"
                                    Text="VM Command" />
                            </StackLayout>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
                <ListView.Triggers>
                    <DataTrigger
                        Binding="{Binding IsBusy}"
                        TargetType="{x:Type ListView}"
                        Value="True">
                        <Setter Property="IsEnabled" Value="False" />
                        <Setter Property="BackgroundColor" Value="{StaticResource ColorYellow}" />
                    </DataTrigger>
                </ListView.Triggers>
            </ListView>

            <CollectionView ItemsSource="{Binding WidgetCollection}">
                <!--#region View when no data-->
                <CollectionView.EmptyView>
                    <Label Text="No items to display" />
                </CollectionView.EmptyView>
                <!--#endregion View when no data-->

                <!--#region View when yes data-->
                <CollectionView.ItemTemplate>
                    <DataTemplate>
                        <Grid Padding="10">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>

                            <Entry BackgroundColor="Lime" Text="{Binding Name}" />
                            <DatePicker BackgroundColor="SaddleBrown" Date="{Binding SomeDate}" />

                            <Button
                                Grid.Row="1"
                                Grid.Column="0"
                                Clicked="Button_OnClicked"
                                Text="UI Layer" />
                            <Button
                                Grid.Row="1"
                                Grid.Column="1"
                                Command="{Binding ModelCommand}"
                                Text="Model Command" />
                            <Button
                                Grid.Row="1"
                                Grid.Column="2"
                                Command="{Binding Source={x:Reference this}, Path=BindingContext.VmCommand}"
                                CommandParameter="{Binding .}"
                                Text="VM Command" />

                        </Grid>
                    </DataTemplate>
                </CollectionView.ItemTemplate>
                <!--#endregion View when yes data-->
            </CollectionView>

            <ListView ItemsSource="{Binding WidgetCollection}">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <StackLayout BackgroundColor="{StaticResource ColorGreen}" Orientation="Horizontal">
                                <StackLayout.Triggers>
                                    <DataTrigger
                                        Binding="{Binding IsSelected}"
                                        TargetType="StackLayout"
                                        Value="true">
                                        <Setter Property="BackgroundColor" Value="{StaticResource ColorRed}" />
                                    </DataTrigger>
                                </StackLayout.Triggers>
                                <Label
                                    BackgroundColor="{StaticResource ColorBlack}"
                                    FontSize="{StaticResource FontSizeRegular}"
                                    Text="{Binding Name}"
                                    TextColor="{StaticResource ColorWhite}" />
                            </StackLayout>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>


            <Button Command="{Binding ResetCommand}" Text="Reset All" />


        </StackLayout>

    </ScrollView>
</ContentPage>

WebApi

$
0
0

when i call WebApi from Xamarin form i get correct Json response from the Api controller
but when i use [authorize] on the Api controller i get a an HTML string of the login page ?
I added basic authentication , username and password to the httpclient header !
Any help would be appreciated .
Thanks

Could not resolve type with token 01000012

$
0
0

I've been developing my app now for at least 5 months. I've been wanting to try the xamarin previewer so i updates visual studio xamarin forms and then i updated my nuget xamarin forms for my portable, ios and android.

now when i try to debug the application on the device i get

System.TypeLoadException: Could not resolve type with token 01000012

on this line

global::Xamarin.Forms.Forms.Init(this, bundle);

which i find very odd

origionally my xamarin forms nuget version was 2.3.3.168

so i thought id update to the stable version which was the same version number 2.3.3.168 but it had "stable" beside it

i've downgraded again but still get the same error.

any thoughts

thanks

How to reduce apk with Android App Bundle and how to build for 64-bit requirement

$
0
0

I have 2 questions both of them about building xamarin forms app for android for google play console, I will ask in one post

  1. I see in google play console that my apk would be smaller if I use Android App Bundle, is there an option in visual studio 2017 to do it? I also opened the apk with android studio and try to do it from there I couldn't make it

  2. Get your apps ready for the 64-bit requirement - I did the check https://developer.android.com/distribute/best-practices/develop/64-bit
    I found the armeabi-v7a I don't have the arm64-v8a or x86_64, so I have 32-bit , how should I build for for 64-bit requirement , is there a way with visual studio 2017 ? what should I do?

Smooth scroll to position when ListView SelectedItem changed

$
0
0

Summary

Automatically scroll the ListView to the selected position when SelectedItem property is changed.
Works on iOS, but not implemented on Android or UWP.

API Changes

Update ListView renderers for Android and UWP.
We have already built this functionality using custom renderers. If approved, can create a PR.

Intended Use Case

Unify the UI behaviour across all three platforms.

how to off nestedscrolling in listview inside scrollview in xamarin forms

$
0
0



<ListView
x:Name="pasengerlist"
SelectionMode="None"
VerticalOptions="FillAndExpand"

                    BackgroundColor="White"
                    HasUnevenRows="true">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ViewCell
                                x:Name="            "
                                  >
                                <StackLayout
                                    Margin="5"
                                    Orientation="Vertical"
                                    VerticalOptions="FillAndExpand"
                                    HorizontalOptions="FillAndExpand">
                                    <Label
                                        Text="{Binding PaxNo}"
                                        TextColor="Red"
                                        FontSize="Micro" />
                                    <StackLayout
                                        Margin="10"
                                        Orientation="Horizontal"

                                        VerticalOptions="CenterAndExpand">
                                        <StackLayout
                                            Orientation="Vertical"
                                            HorizontalOptions="StartAndExpand">
                                            <Label
                                                Text="FIRST NAME"
                                                TextColor="Gray"
                                                FontSize="Micro" />
                                            <Frame
                                                BackgroundColor="White"
                                                BorderColor="Gray"
                                                CornerRadius="0"
                                                Padding="0"
                                                HasShadow="false">
                                                <Label
                                                    x:Name="fromname"
                                                    Text="{Binding FirstName}"
                                                    BackgroundColor="Transparent"
                                                    Margin="5"
                                                    FontSize="Micro"
                                                    TextColor="Black" />
                                            </Frame>
                                        </StackLayout>
                                        <StackLayout
                                            Orientation="Vertical"
                                            HorizontalOptions="CenterAndExpand">
                                            <Label
                                                Text="LAST NAME"
                                                TextColor="Gray"
                                                FontSize="Micro" />
                                            <Frame
                                                BackgroundColor="White"
                                                BorderColor="Gray"
                                                HasShadow="false"
                                                Padding="0"
                                                CornerRadius="0">
                                                <Label
                                                    x:Name="lastname"
                                                    Text="{Binding LastName}"
                                                    BackgroundColor="Transparent"
                                                    Margin="5"
                                                    FontSize="Micro"
                                                    TextColor="Black" />
                                            </Frame>
                                        </StackLayout>
                                        <StackLayout
                                            Orientation="Vertical"
                                            HorizontalOptions="EndAndExpand">
                                            <Label
                                                Text="GENDER"
                                                TextColor="Gray"
                                                FontSize="Micro" />
                                            <Frame
                                                BackgroundColor="White"
                                                HasShadow="false"
                                                BorderColor="Gray"
                                                Padding="0"
                                                CornerRadius="0">
                                                <Label
                                                    Text="{Binding Gender}"
                                                    Margin="5"
                                                    TextColor="Black"
                                                    FontSize="Micro" />
                                            </Frame>
                                        </StackLayout>
                                    </StackLayout>

                                    <BoxView
                                        Color="Silver"
                                        HeightRequest="1"
                                        HorizontalOptions="FillAndExpand" />
                                    <!--// end -->
                                    <StackLayout
                                        Margin="10"
                                        Orientation="Horizontal"
                                        VerticalOptions="Center">
                                        <StackLayout
                                            Orientation="Vertical"
                                            HorizontalOptions="StartAndExpand">
                                            <Label
                                                Text="MEAL AMOUNT : "
                                                TextColor="Gray"
                                                FontSize="Micro" />
                                            <Frame
                                                BackgroundColor="White"
                                                IsVisible="{Binding additonalservicevisibility1}"
                                                BorderColor="Gray"
                                                HasShadow="false"
                                                Padding="0"
                                                CornerRadius="0">
                                                <Picker
                                                    x:Name="meals"
                                                    BackgroundColor="Transparent"
                                                    Title="Select Here"
                                                    SelectedIndexChanged="Handle_PickerChanged"
                                                    ItemsSource="{Binding AdditionalServiceSelect.MealValueLst}"
                                                    ItemDisplayBinding="{Binding MealServiceName}"
                                                    FontSize="Micro"
                                                    TextColor="Black">
                                                </Picker>
                                            </Frame>
                                            <Label
                                                IsVisible="{Binding additonalservicevisibility2}"
                                                Text="Meals not Available!"
                                                FontSize="Micro"
                                                TextColor="Black" />
                                        </StackLayout>

                                    </StackLayout>
                                    <StackLayout
                                        IsVisible="false"
                                        Orientation="Horizontal"
                                        HorizontalOptions="StartAndExpand">
                                        <Label
                                            x:Name="totalamountMB"
                                            Text="TOTAL AMOUNT : "
                                            TextColor="Black"
                                            FontSize="Small"
                                            FontAttributes="Bold"
                                            Margin="10,0,0,0" />
                                        <Label
                                            Text="{Binding TotalAmount}"
                                            TextColor="Black"
                                            FontSize="Small"
                                            FontAttributes="Bold"
                                            Margin="10,0,0,0" />
                                    </StackLayout>
                                    <BoxView
                                        Color="Silver"
                                        HeightRequest="1"
                                        HorizontalOptions="FillAndExpand" />
                                    <StackLayout
                                        Margin="10"
                                        Orientation="Horizontal"
                                        VerticalOptions="Center">
                                        <StackLayout
                                            Orientation="Vertical"
                                            HorizontalOptions="StartAndExpand">
                                            <Label
                                                Text="AIRLINE NAME"
                                                TextColor="Gray"
                                                FontSize="Micro" />
                                            <Frame
                                                BackgroundColor="White"
                                                HasShadow="false"
                                                BorderColor="Gray"
                                                CornerRadius="0"
                                                Padding="0">
                                                <Label
                                                    Text="{Binding Airname}"
                                                    BackgroundColor="Transparent"
                                                    Margin="5"
                                                    FontSize="Micro"
                                                    TextColor="Black" />
                                            </Frame>
                                        </StackLayout>
                                         <StackLayout
                                            IsVisible="true"
                                            Orientation="Vertical"
                                            HorizontalOptions="EndAndExpand">
                                            <Label
                                                Text="FREQUENT FLYER NO."
                                                TextColor="Gray"
                                                FontSize="Micro" />
                                            <Frame
                                                BackgroundColor="White"
                                                BorderColor="Gray"
                                                HasShadow="false"
                                                Padding="0"
                                                CornerRadius="0">
                                                <Label
                                                    BackgroundColor="Transparent"
                                                    FontSize="Micro"
                                                    Margin="5"
                                                    TextColor="Black" />
                                            </Frame>
                                        </StackLayout>
                                        <StackLayout
                                             VerticalOptions="Center"
                                            HorizontalOptions="EndAndExpand">
                                            <Label
                                                Text="Get Employee"
                                                IsVisible="{Binding GetPasssengerVisibility}"
                                                VerticalOptions="Center"
                                                TextColor="Green"
                                                FontAttributes="Bold"
                                                FontSize="Small"
                                                HorizontalOptions="EndAndExpand" />
                                            <Label.GestureRecognizers>
                                                <TapGestureRecognizer
                                                    Tapped="Ondetaillabeltapped"
                                                    NumberOfTapsRequired="1" />
                                            </Label.GestureRecognizers>
                                        </StackLayout>

                                    </StackLayout>
                                </StackLayout>
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>

                <Label
                    Margin="0,0,10,0"
                    x:Name="baggageAmount"
                    HorizontalOptions="EndAndExpand"
                    Text=" Baggage Amount : 0 "
                    TextColor="Black"
                    FontSize="Micro" />
                <Label
                    Margin="0,0,10,0"
                    x:Name="wholetotalamount"
                    HorizontalOptions="EndAndExpand"
                    Text="Total Amount : 0"
                    TextColor="Black"
                    FontSize="Micro" />
                </StackLayout>
        </ScrollView>

Expander

$
0
0

Is there a way to put and expander inside a ContentPage? I have a MasterDetailPage app and i would like to have sort of an expander; like the one used by gmail app where you specify multiple gmail accounts; then you can hit the expander and switch between accounts.

i have attached an example image

Thanks
Nick

Filter-able Picker/Lookup control

$
0
0

Hi Guys,

I am looking for some plug-in or snap on code (no custom renderers please)
For a functionality like shown below.

I tried implementing this with https://github.com/rotorgames/Rg.Plugins.Popup, with a ListView, however the binding does not work with the control template.

Can you guys please suggest any better option? (or even how to get this working - small POC, please).

Thanks,
N Baua


Get Version Number and Version Name from the Android Manifest in Xamarin MyForm.xmal.cs file?

$
0
0

Xamarin Forms Users,

Please help, with a questions about getting information about an app at run time, using Xamarin Forms, with C#, via Visual Studio Community 2019.

How can one...

Get Version Number and Version Name from the Android Manifest in Xamarin "MyForm.xaml.cs" file?

Please advise.

Thanks.

-- Mark Kamoski

using System;
using Xamarin;
using Xamarin.Forms;

namespace Consecration2019
{
    public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            this.InitializeComponent();
        }

        private void PickStartDay_Clicked(object sender, EventArgs e)
        {
            Application.Current.MainPage = new StartPickerPage();
        }

        private void GetAppDetails_Clicked(object sender, EventArgs e)
        {
            string myVersionName = string.Empty;

            //I have tried this but "Context" does not exist.
            //
            //var myVersionName = Context.PackageManager.GetPackageInfo(Context.PackageName, 0).VersionName;

            //I have tried this but "Application" does not contain a definition for "Context" here.
            //
            //string myVersionName = Application.Context.ApplicationContext.PackageManager.GetPackageInfo(Application.Context.ApplicationContext.PackageName, 0).VersionName;

            this.DisplayAlert(title: "App Details", message: "Note myVersionName='" + myVersionName + "' here.", cancel: "Ok");
        }
    }
}

Cancel webview navigation event, e.Cancel = true not working.

How can I prevent labels from taking up all available horizontal space when word wrapping?

$
0
0

I have labels inside a grid and I want them to take up only the necessary space to fit the text. With short messages this works correctly, but with longer messages that text wrap the label fills the available space even though the way the words wrapped means that it doesn't need it.

My account isn't allowed to post direct links yet but here is a screenshot:
photos.google.com/share/AF1QipNDOK7HtPb3rLREC2dhufaKCA9CnSpIqk-rRJTSSKQa-XO9c8UzNbHxVEMpfKlMOQ/photo/AF1QipMVZVv3ciXt9xafg_cfkVU68Te9_iwamMrWB7A6?key=ZDdjTnRpQkZaeWRfcU0yOXljZGNsTEdDS3p3XzdB

As you can see, the pink label takes up only the necessary amount of space, while the aquamarine one expanded to fill the available space despite having a large area on the right that doesn't have any text in it.

I've tried searching for solutions with no luck. The only thread I found that even mentions this problem has two developers bickering about whether or not the one trying to help actually understands what the problem is, and a solution is never posted. Does anyone know how to fix this?

XAML:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="90"/>
</Grid.ColumnDefinitions>
<Label BackgroundColor="Aquamarine"
HorizontalTextAlignment="Left"
HorizontalOptions="Start"
Grid.Row="0" Grid.Column="0">
Hippopotamus vocabulary accentuates educational imbalances. Gymnastic crocodilians abbreviate gratuitously enourmous nomenclature.
</Label>
<Label BackgroundColor="Pink"
HorizontalTextAlignment="Left"
HorizontalOptions="Start"
Grid.Row="1" Grid.Column="0"
Margin="0,0,90,0">
Short.
</Label>
<StackLayout Grid.Row="0" Grid.Column="1" BackgroundColor="Yellow" HorizontalOptions="FillAndExpand"></StackLayout>
<StackLayout Grid.Row="1" Grid.Column="1" BackgroundColor="Green" HorizontalOptions="FillAndExpand"></StackLayout>
</Grid>

Adding index to xamarin picker

$
0
0

Hi all
Can I add item and index to xamarin picker
in asp.net I use this code

DropDownList1.Items.Add(New ListItem("English","EN"))

but in Xamarin forms I can only add Item

 Picker1.Items.Add("English");

Is there a way to add the index, because I want to retrieve the index value?

Thank you in advance

Floating Action Button with Listview inside a TabbedPage.

$
0
0

I want to add FAB in a view that has listview in it and that view is in TabbedPage Contentpage.
Here is my code (Giving Error : The property 'Content' is set more than once.

<TabbedPage xmlns="..." xmlns:x="..." xmlns:fab="clr-namespace:FAB.Forms;assembly=FAB.Forms" x:Class="IIOT_PB.Views.DevView" Title="{DynamicResource projectopen}" BarBackgroundColor="#1976D2"> <ContentPage Title="Devices"> <ContentPage.Content> <ListView x:Name="devicesList" VerticalOptions="Fill" HorizontalOptions="Fill" SeparatorVisibility="Default" RowHeight="55" BackgroundColor="{DynamicResource backgroundColor}" ItemTapped="DevicesList_ItemTapped" SelectionMode="None"> <ListView.ItemTemplate> <DataTemplate> <ViewCell> <StackLayout Orientation="Horizontal" VerticalOptions="Fill" HorizontalOptions="Fill"> <StackLayout VerticalOptions="StartAndExpand" HorizontalOptions="StartAndExpand" Orientation="Vertical"> <Label Text="{Binding name}" FontSize="Small" FontAttributes="Bold" VerticalOptions="Start" TextColor="{DynamicResource textColor}"/> <Label Text="{Binding description}" LineBreakMode="TailTruncation" WidthRequest="250" FontSize="Small" VerticalOptions="StartAndExpand" TextColor="{DynamicResource textColor}"/> </StackLayout> <ImageButton Padding="15,15,15,15" Source="about.png" Clicked="Button_Clicked" VerticalOptions="End" AutomationId="{Binding id}" HorizontalOptions="Fill" BackgroundColor="Transparent"/> </StackLayout> </ViewCell> </DataTemplate> </ListView.ItemTemplate> </ListView> <fab:FloatingActionButton x:Name="FAB" HorizontalOptions="CenterAndExpand" WidthRequest="50" HeightRequest="50" VerticalOptions="CenterAndExpand"/> </ContentPage.Content> </ContentPage>

Floating Action Button with Listview inside a TabbedPage.

$
0
0

I want to add a FAB in a view having listview that is in TabbedPage ContentPage.
Here's my code...Error XLS0501 The property 'Content' is set more than once.

<TabbedPage xmlns="..."
        xmlns:x="..."
        xmlns:fab="clr-namespace:FAB.Forms;assembly=FAB.Forms"
        x:Class="IIOT_PB.Views.DevView" Title="{DynamicResource projectopen}" BarBackgroundColor="#1976D2">
<ContentPage Title="Devices">
    <ContentPage.Content>
        <ListView x:Name="devicesList" VerticalOptions="Fill" HorizontalOptions="Fill"
                      SeparatorVisibility="Default" RowHeight="55" BackgroundColor="{DynamicResource backgroundColor}"
                      ItemTapped="DevicesList_ItemTapped" SelectionMode="None">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <StackLayout Orientation="Horizontal" VerticalOptions="Fill" HorizontalOptions="Fill">
                                <StackLayout VerticalOptions="StartAndExpand" HorizontalOptions="StartAndExpand"
                                         Orientation="Vertical">
                                    <Label Text="{Binding name}"
                                       FontSize="Small" FontAttributes="Bold"
                                       VerticalOptions="Start"
                                       TextColor="{DynamicResource textColor}"/>
                                    <Label Text="{Binding description}" LineBreakMode="TailTruncation" WidthRequest="250"
                                       FontSize="Small"
                                       VerticalOptions="StartAndExpand"
                                       TextColor="{DynamicResource textColor}"/>
                                </StackLayout>
                                <ImageButton Padding="15,15,15,15" Source="about.png" Clicked="Button_Clicked" VerticalOptions="End" AutomationId="{Binding id}" HorizontalOptions="Fill" BackgroundColor="Transparent"/>
                            </StackLayout>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
            <fab:FloatingActionButton x:Name="FAB" HorizontalOptions="CenterAndExpand" WidthRequest="50" HeightRequest="50"  VerticalOptions="CenterAndExpand"/>
    </ContentPage.Content>
    </ContentPage>

Setting Icon File Names as Resources

$
0
0

I was trying to get all of my icon file definitions in one place so that it would be easy to swap icon sets in the future. Since I use XAML for my page definitions, I thought I'd make a ResourceDictionary with all of my icons. Just trying to get it to work, I put one in my App.xaml file:

<?xml version="1.0" encoding="utf-8"?>
<Application xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:MyApp"
    x:Class="MyApp.App">

    <Application.Resources>
        <ResourceDictionary>       
            <x:String x:Key="SettingsIcon">"outline_settings_white_48.png"</x:String>
            <!-- rest of file deleted for brevity -->
        </ResourceDictionary>
    </Application.Resources>
</Application>

Then in my xaml, I access it like this:

<ImageButton
    x:Name="SettingsButton"
    Source="{StaticResource SettingsIcon}"
    Clicked="GoSettings"/>

This generates a run-time error (in the application output window):

Could not load image named: {0}: "outline_settings_white_48.png"
FileImageSourceHandler: Could not find image or image file was invalid: File: "outline_settings_white_48.png"

... and of course the icon is not displayed.

If I reference the icon directly, it works just fine:

<ImageButton
    x:Name="SettingsButton"
    Source="outline_settings_white_48.png"
    Clicked="GoSettings"/>

I have tried it without the .png extension, and got the same result.

What am I doing wrong?

Thanks!

P.S. Right now I only need it to work on Android.


Simple: Binding an IEnumerable ...is there a better way???

$
0
0

I'm tying to bind an IEnumerable<View> to a StackLayout.

My current solution is pretty weak Kung-Fu......

protected override void OnBindingContextChanged()
{
    base.OnBindingContextChanged();

    foreach(var v in ((MyViewModel)BindingContext).Views )
    { 
        MyDisplay.Children.Add(v);
    }
}

Is there a better way???

Error when export APK and install this APK file with Xamarin Forms

$
0
0

I have used release mode and debug mode too with Xamarin.forms:

Build-> Archive for Publishing wizard.
After publishing, I selected Ad Hoc and saved the APK to my local drive.

I have min SDK version API level 15 (4.0.3) with target API 23, I have required permission.
I have selected all items from list on Suported ABIs (armeabi, armeabi-v7a, x86, x86_64 and arm64-v8a)
I test with my Nexus 5 with 6.0.1 but I send APK

Always show same error...
(Spanish) Error de análisis
se ha producido un error al analizar el paquete

(English) Parse error
There was a problem parsing the package

I have tested with my custom application and I have generated a sample APK for this library
https://components.xamarin.com/view/zxing.net.mobile.forms

Why?

iOS page covers status bar

$
0
0

What should I do to prevent the application cover the status bar area?
It covers the whole window and status icons are visible through top_grid on iPad 2 simulator


<?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="test_cs_mobile_xamarin.main_page">
   <StackLayout>
      <Frame x:Name="top_frame" HasShadow="true" OutlineColor="Green" Padding="5,5,5,5" VerticalOptions = "FillAndExpand">
         <ScrollView  x:Name="top_scroll_view" VerticalOptions = "FillAndExpand">
            <Grid x:Name="top_grid" VerticalOptions = "FillAndExpand">
               <Grid.Children>
               </Grid.Children>
            </Grid>
         </ScrollView>
      </Frame>
      <Frame x:Name="bottom_frame" HasShadow="true" OutlineColor="Green" Padding="5,5,5,5" VerticalOptions = "FillAndExpand">
         <ScrollView x:Name="bottom_scroll_view" VerticalOptions = "FillAndExpand">
            <Label  Text="..." XAlign="Start" YAlign="Start" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" x:Name="bottom_label" LineBreakMode="WordWrap" />
         </ScrollView>
      </Frame>
      <StackLayout x:Name="bottom_stack_layout" Orientation="Horizontal">
         <Button Text="Add 1" x:Name="button_1"></Button>
         <Button Text="Add 2" x:Name="button_2"></Button>
         <Button Text="http" x:Name="button_3"></Button>
         <Button Text="http 1" x:Name="button_4"></Button>
      </StackLayout>
   </StackLayout>

Can't create new Prism project

$
0
0

Hi, I can't create a new Prism (Xamarim.Forms) project anymore 'cause I'm getting this error

Requested value 'autofac' was not found

from visual studio when I try to create the project. I've tried with both visual studio 2017 and 2019, 'till few days ago I had no problems creating Prism projects and I have no idea of what changed.

Xamarin.Forms Android FileProvider: Java.Lang.NullPointerException when trying to read file

$
0
0

I've been trying generate word files and open it on an Android using Xamarin.Forms. I can create the file, but the following error is thrown when I try to read:

Java.Lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference

The code I'm using is as follows:

The AndroidManifest.xml contains:

<application>
    <provider android:name="android.support.v4.content.FileProvider"
        android:authorities="com.ESFJP.ESFAtas.fileprovider"
        android:grantUriPermissions="true"
        android:exported="false">
            <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths"/>
    </provider>
</application>

The provider_paths.xml, which lies in the folder Resources/xml, is:

<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path name="external_files" path="/Atas"/>
    <files-path name="files" path="/Atas"/>
</paths>

The async method to save the file and open:

public async Task Save(string fileName, string contentType, MemoryStream stream)
{
    string exception = string.Empty;
    string root = null;
    if (Android.OS.Environment.IsExternalStorageEmulated)
    {
        root = Android.OS.Environment.ExternalStorageDirectory.ToString();
    }
    else
        root = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

    Java.IO.File myDir = new Java.IO.File(root + "/Atas");
    myDir.Mkdir();
    Java.IO.File file = new Java.IO.File(myDir, fileName);

    if (file.Exists()) file.Delete();


    try
    {
        //The permission failure happens in this line when the target version is set to API Level 27 Nougat
        FileOutputStream outs = new FileOutputStream(file);
        stream.Position = 0;
        outs.Write(stream.ToArray());
        outs.Flush();
        outs.Close();
    }

    catch (Exception e)
    {
        //The permission failure can be seen here if the target version is set to API level 27 Nougat
        exception = e.ToString();
    }
    finally
    {
        stream.Dispose();
    }

    if (file.Exists())
    {
        string auth = "com.ESFJP.ESFAtas.fileprovider";
        string extension = Android.Webkit.MimeTypeMap.GetFileExtensionFromUrl(Uri.FromFile(file).ToString());
        string mimeType = Android.Webkit.MimeTypeMap.Singleton.GetMimeTypeFromExtension(extension);
        if (mimeType == null)
            mimeType = "*/*";

        //The Java.Lang.NullPointerException is thrown from this line \/\/\/
        Uri uri = FileProvider.GetUriForFile(Forms.Context, auth, file);

        Intent intent = new Intent(Intent.ActionView);
        intent.SetDataAndType(uri, mimeType);
        intent.AddFlags(ActivityFlags.GrantReadUriPermission | ActivityFlags.GrantWriteUriPermission);
        intent.AddFlags(ActivityFlags.NewTask | ActivityFlags.NoHistory);

        var resInfoList = Forms.Context.PackageManager.QueryIntentActivities(intent, PackageInfoFlags.MatchDefaultOnly);
        foreach (var resolveInfo in resInfoList)
        {
            var packageName = resolveInfo.ActivityInfo.PackageName;
            Forms.Context.GrantUriPermission(packageName, uri, ActivityFlags.GrantWriteUriPermission | ActivityFlags.GrantPrefixUriPermission | ActivityFlags.GrantReadUriPermission);
        }

        Forms.Context.StartActivity(intent);
    }
}

I've been struggling with this code. Many threads told about the issue being on the provider_paths.xml, but I can't figure out why or where or even if it's actually there.

Also, a small note. If you set the Targed Android version to Use Compile using SDK version the app manages to at least create the file, but it won't open, giving the Java.Lang.NullPointerException mentioned above. IF you set it to Android 8.1 (API Level 27 - Oreo), it won't manage to create the file. It says that the permission has not been granted at this line exception = e.ToString();. I've marked the line where that happens, it's on the public async Task Save(string fileName, string contentType, MemoryStream stream).

I created a sample in my GitHub where this issue happens: https://github.com/RaelsonCraftz/XamarinFileProviderSample. Any help is appreciated!

Viewing all 76418 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>