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

Application is breaking when i am running on emulator with API 19..

$
0
0

Application is breaking when i running on emulator with API 19 and getting this error see this screenshot.


Android Bluetooth permission triggering OnAppearing/OnDisappearing

$
0
0

Hi all,

I've stumbled across something that doesn't feel right, but might be worth mentioning.

I have an app that needs to connect to Bluetooth. For this I need to make sure the Bluetooth is on. To turn it on, I ask for the user's permission using the following code (Android only):

Intent enableBtIntent = new Intent(BluetoothAdapter.ActionRequestEnable);
MainActivity.Instance.StartActivityForResult(enableBtIntent, BluetoothRequestCode);

MainActivity.Instance refers to a property in the MainActivity which contains the MainActivity instance.

This code works fine. I get the prompt to ask the user to allow the app to turn on Bluetooth.

The issue comes when this prompt appears, the OnDisappearing() method is triggered, and when I allow/deny Bluetooth access, the OnAppearing() method is triggered.

Given that the prompt appears a simple dialog, I wouldn't expect the page to be "disappearing" when the dialog is opened, and then "reappearing" when the dialog is closed. Is this expected behaviour? If not, am I doing something wrong?

Thanks!

login via social Media

$
0
0

I am trying to add to my application a login via social Media (Facebook, Google+ and Tweeter) . I searched the web for a xamarin.forms solution but all solution I found use xamarin.droid and xamarin.ios I didn't found any solution based on xamarin.forms . Any Idea or help about a Library that work with Xamarin.forms?
I tried xamarin.Auth and xamarin.facebook.android and xamarin.facebook.ios .... all these library are native

Scrolldown in ListView using ItemAppearing event skips records in Xamarin.Forms

$
0
0

Hi,

I have ListView in Xamarin Page. I use ItemAppearing event to scroll down. ListViewCell height is big so 1 screen cover first and 80% part of second viewcell.

Steps to load more data for scroll down:

  1. Initially when page load, it call API and get 10 records in
    EmployerResult List. That will be added in ListView using
    databinding.
  2. Having ItemAppearing event. There is a condition in this event.
    When last cell start to appear, it will call API and again append 10
    record in List object of ViewModel.
  3. So, this way it will call to API and append 10 record everytime when
    last cell start to appear.

Now the point is on every load, it skips last record and show first record of next 10 record. However sometimes it skips 2-3 records if user scrolldown fastly.

i.e if I have 10 records first time. Now I am on 9th record and I am scrolling down to 10. 10th record is starting to appear and API call fires. After this call completed, screen will show 11th record at top of the screen. Here, 10th record is skipped. This way user will see 11th record rather 10th. Here user need to scrollup again to see 10th record.

Sometimes, it skips 2-3 records if user scrolldown fastly.

Can anybody please suggest me?

Code

XAML

<ListView Grid.Row="0" x:Name="EmployerResultsListView"
          ItemsSource="{Binding EmployerResults}"
          HasUnevenRows = "true"
          SeparatorVisibility="None"
          IsPullToRefreshEnabled="true"
          RefreshCommand="{Binding RefreshCommand}"
          IsRefreshing="{Binding IsRefreshing, Mode=OneWay}"
          ItemAppearing="Handle_ItemAppearing"
          ItemTapped="OnEmployerResultsListViewItemTapped">
    <ListView.ItemTemplate>
        <DataTemplate>
            <local:EmployerResultViewCell />
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

XAML.CS

private void Handle_ItemAppearing(object sender, ItemVisibilityEventArgs e)
{
    var itemTypeObject = e.Item as EmployerProfile;
    if (_viewModel.EmployerResults.Last() == itemTypeObject && _viewModel.EmployerResults.Count() != 1)
    {
        if (_viewModel.LoadMoreCommand.CanExecute(null))
        {
            _viewModel.LoadMoreCommand.Execute(null);
        }
    }
}

ViewModel

public EmployerResultsViewModel()
{
    LoadMoreCommand = new RelayCommand(LoadMoreEmployerResult, () => !IsBusy);
    EmployerResults = new ObservableRangeCollection<EmployerProfile>();
}
public ObservableRangeCollection<EmployerProfile> EmployerResults { get; set; }

private async void LoadMoreEmployerResult()
{
    IsBusy = true;
    EmployerResults.AddRange((await _employerApiClient.GetMoreData(pagenumber)));
    IsBusy = false;
}

System.IO.FileNotFoundException error to build Android project in Xamarin.Forms

$
0
0

I am not able to build my Android project of Xamarin.Form. However, iOS project works fine.

I have tried by remove all DLLs from Package and Bin folders but it doesn't work.

Can anybody guide me?

Error: Exception while loading assemblies:
System.IO.FileNotFoundException: Could not load assembly 'Xamarin.iOS,
Version=0.0.0.0, Culture: neutral, PublicKeyToken=84exxxxxxxx'.
Perhaps it doesn't exist in the Mono for Android Profile?

enter image description here

DLLs with version

enter image description here

enter image description here

enter image description here

[Xamarin Blog] Using Custom Controls in Xamarin.Forms on Android

Drag map up and down inside Scrollview

$
0
0

Hi. I've a map inside a Scrollview among other elements. When I try to drag the map up and down the scrollview scrolls and not the map. It only happens in Android.
I've been able to hack it a little bit and make it work with a map renderer but it fails in some cases.
Is there any other way to fix this?

Thanks in advance.

Hunting Memory Leaks, best practices?

$
0
0

Hi,

I started a new Thread because this Title makes more sense.

What are your best strategies to hunt down MemoryLeaks, especialls on Android? How can I check if a certain object get's relased? Does it make sense to include a Debug.WriteLine into the Destructor of the Class of interest?

Does it make sense to call GC.Collect to see if memory stays constant?

Thanks for all help!

Best
Thomas


Google maps Integration

$
0
0

Hey Everyone, we had a specific set of requirement and that's related to the Maps. We are using Xamarin.Forms in this project.

  1. Display Google maps on both Android and iOS.
  2. Get current location of the device.
  3. Provide the user with the ability to search new place i.e. A to B Route.
  4. Show Polyline graph from A to B.
  5. Also, show the current location as the user moves from A to B.

Can you please guide me what will the best approach for this.

Things I tried till the time
1. tried to integrate Google API maps using WebView, no success I am not able to load the HTML code shared in the Example.
2. Second I am trying to follow the github example of maps custom renderer but in that example hardcoded LAT Long are listed. Not sure how I will be able to get the RouteCordinates for dynamic positions

Thanks

How to access xaml elements that is inside another xaml?

$
0
0

I have a view that is reference in two different content pages. How can I access the content view properties that inside the content page? I want to access "myLabel" properties from the content page.

Content View and Content Page

<?xml version="1.0" encoding="UTF-8"?>
<ContentView 
    xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
    x:Class="MyProject.Views.MyView">
    <StackLayout
        VerticalOptions="End"
        Orientation="Horizontal"
        HorizontalOptions="FillAndExpand"
        Spacing="0">
        <Entry
            x:Name="myEntry"
            HorizontalOptions="End"
            HeightRequest="40"
            WidthRequest="40">
        </Image>
    </StackLayout>
</ContentView>

<?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:view="clr-namespace:MyProject.Views;assembly=MyProject"
    x:Class="MyProject.Pages.MyPage">
    <ContentPage.Content>
        <StackLayout
            Orientation="Vertical"
            VerticalOptions="FillAndExpand"
            Spacing="0">
            <view:MyView/>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

Is there a package as iCarousel in xamarin forms.

$
0
0

I have been trying to implement the cylindrical animation to the horizontal listview to achieve the iCarousel cylindrical effect.Here is the sample I have tried .

<ContentPage.Resources>
    <ResourceDictionary>
         <xamanimation:StoryBoard 
            x:Key="empListViewAnimation"         
            Target="{x:Reference empListView}">
            <xamanimation:TranslateToAnimation TranslateY="90" Easing="SpringOut" Duration="800" />
        </xamanimation:StoryBoard>
    </ResourceDictionary>
</ContentPage.Resources>
<ContentPage.Triggers>
    <EventTrigger Event="Appearing">
        <xamanimation:BeginAnimation   
            Animation="{StaticResource empListViewAnimation}" />
    </EventTrigger>
</ContentPage.Triggers>
<ContentPage.Content>
    <StackLayout Spacing="0">
        <!-- <xamanimation:StoryBoard x:Key="empListViewAnimation" Target="{x:Reference empListView}">
            <xamanimation:TranslateToAnimation TranslateY="600" Duration="0" />
            <xamanimation:TranslateToAnimation TranslateY="0" Easing="SpringOut" Duration="800" />
        </xamanimation:StoryBoard>-->
        <Controls:HorizontalList  x:Name="empListView"  ListOrientation="Horizontal" HeightRequest="300" BackgroundColor="Transparent" ItemsSource="{Binding}" Margin="10,0,10,0">
            <Controls:HorizontalList.ItemTemplate>
                <DataTemplate>
                    <templates:ServiceItemTemplate />
                </DataTemplate>
            </Controls:HorizontalList.ItemTemplate>
        </Controls:HorizontalList>
    </StackLayout>
</ContentPage.Content>

and this is the service template

<ContentView.Content>
    <Grid>
        <Controls:AnimatedDonutChart x:Name="DonutChart" Percentage="{Binding Percentage}"  StrokeHeight="15" DefaultColor="Gray" ValueColor="Purple" WidthRequest="150" HeightRequest="200" />
    </Grid>
</ContentView.Content>

Changing text color of status bar when new page is pushed

$
0
0

Hey,

I'm trying to achieve the following:
My app usually has a black text for the status bar, but for certain screens the App changes in a full screen version with a dark background color, so i want to change the status bar text color to white. I know that in iOS i can change the color in info.plist but i don't understand how i can only change it for these certain forms pages. I researched my problem and i know that it's also possible to change the color regarding to your NavigationBar TintColor but i don't have a NavigationBar at these pages.

Any solutions or maybe a code example how i can change the status bar text color in a CustomRenderer?
Thanks in advance!

Cant seem to get a binding to work (BooleanToObjectConverter and ImageResourceExtention).

$
0
0

Hello everyone.
I have been following https://blog.xamarin.com/behaviors-in-xamarin-forms/ and the referenced material on git to recreate the email checkmark.
While the EmailValidatorBehaviour seems to work, there is no image appearing. ( I looked at https://developer.xamarin.com/guides/xamarin-forms/user-interface/images/#Embedded_Images to be sure)
When I put breakpoints in the BooleanToObjectConverter and ImageResourceExtention classes, they dont get hit. (Only when the app is launched, when the xaml is initialized.)
I put the xaml code below.
The experience I have with Xamarin and C# is limited. However I have programmed for many years.~~~~

Can someone point me into the right direction?
Thanks in advance.

<?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:HanzeStudentX;assembly=HanzeStudentX"
             xmlns:conv="clr-namespace:HanzeStudentX.Util.Converters"
             xmlns:img="clr-namespace:HanzeStudentX.Util.Extentions"
             xmlns:beh="clr-namespace:HanzeStudentX.Util.Behaviours"
             x:Class="HanzeStudentX.MainPage"
             BackgroundColor="Orange">
    <ContentPage.Resources>
        <ResourceDictionary>
            <conv:BooleanToObjectConverter x:Key="boolToStyleImage" x:TypeArguments="Style">
                <conv:BooleanToObjectConverter.FalseObject>
                    <Style TargetType="Image">
                        <Setter Property="Source" Value="{img:ImageResource HanzeStudentX.Images.Isuccess.png}" />
                    </Style>
                </conv:BooleanToObjectConverter.FalseObject>

                <conv:BooleanToObjectConverter.TrueObject>
                    <Style TargetType="Image">
                        <Setter Property="Source" Value="{img:ImageResource HanzeStudentX.Images.success.png}" />
                    </Style>
                </conv:BooleanToObjectConverter.TrueObject>
            </conv:BooleanToObjectConverter>
        </ResourceDictionary>
    </ContentPage.Resources>
<Grid  VerticalOptions="FillAndExpand">
        <Grid.RowDefinitions>
            <RowDefinition Height="2*"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="2*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="10"/>
            <ColumnDefinition Width="3*" />
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="10" />
        </Grid.ColumnDefinitions>
        <Label
            HorizontalOptions="Center"
            Grid.Row="0"
            Grid.Column="1"
            Grid.ColumnSpan="2"
            FontAttributes="Bold"
            Text="HanzeStudent"
            FontSize="Large"
            />
        <Entry 
            Grid.Row="1" 
            Grid.Column="1" 
            x:Name="studentemailfield"  
            Placeholder="Student Email" 
            HorizontalOptions="Fill" 
            BackgroundColor="White" 
            TextColor="Black" >
            <Entry.Behaviors>
                <beh:EmailValidatorBehavior x:Name="emailValidator" />
            </Entry.Behaviors>
        </Entry>
        <Image
            Grid.Row="1"
            Grid.Column="2"
            x:Name="emailSuccessErrorImage"
            Style="{Binding Source={x:Reference emailValidator}, Path=IsValid, Converter={StaticResource boolToStyleImage}}"

            />
        <Entry 
            Grid.Row="2" 
            Grid.Column="1" 
            x:Name="passwordfield" 
            Placeholder="Password" 
            IsPassword="true" 
            HorizontalOptions="Fill" 
            BackgroundColor="White"  
            TextColor="Black"/>
        <ActivityIndicator  
            Grid.Row="2" 
            Grid.Column="2" 
            Color="White"
            x:Name="loginactivityindicator"
            HorizontalOptions="Center" 
            VerticalOptions="Center"/>
        <Button 
            Grid.Row="3"
            Grid.Column="1"
            Grid.ColumnSpan="2"
            x:Name="loginbutton"
            Text="Login"
            TextColor="Black"
            BackgroundColor="Red"
            BorderColor="White"
            Clicked="Button_Clicked" />
    </Grid>
</ContentPage>

error code CS0050 and CS0053 how to fix it

$
0
0

Error CS0050 Inconsistent accessibility: return type 'Task' is less accessible than method 'GoogleServices.GetGoogleUserProfileAsync(string)'

Error CS0053 Inconsistent accessibility: property type 'GoogleProfile' is less accessible than property 'GoogleViewModel.GoogleProfile'


Connecting to websocket stomp server

$
0
0

Hello,
I'm developing an xamarin app and I am having a hard time connecting to a working Spring server using stomp. I need to connect to the endpoint and subscribe to the notifications message broker? Can anyone help me with a working implementation please?
I have found this library https://github.com/krlito/StompNet this could be useful but I think it's outdates when i try to install it I get : "You are trying to install this package into a project that targets 'MonoAndroid,Version=v7.1', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author"


Handle event when contact actions menu is opened in Android

$
0
0

If I open the context menu on a listview item (long press) the context menu will open, after which the user can press one of the menu options (context actions), like for example "Delete" or "Cancel".

What I like to achieve is to handle the event of when the context menu is opened. So not the event of when the user has chosen / pressed an option.

Why?

If I have selected listview item X (which then gets a different "selected" color) and then open the context menu on listview item Y (so a different one), that one also gets a selected color. Now there are 2 items selected which is confusing for the user: "which item will be affected by the context menu?".

So in the desired event handler I want to de-select the other item (in this example X) and only select Y (on which I opened the context menu) and/or give Y an other background color.

Can this be done?

NB: I don't need a solution for iOS as iOS uses a swipe menu, which by design clearly shows on which item you will perform the action.

Xamarin forms Custom toolbar

$
0
0

Hi,
I want to create custom toolbar like this in xamarin forms

how to create?

Change text color of ListView using C#

$
0
0

Can you change the text color of a ListView using C#? I have a ListView inside a StackLayout that inside another StackLayout. I have all the code in C# without any XAML file.

thanks

How to handle different screen sizes

$
0
0

Hi,

are there any tutorials for xamarin forms on how to handle different screen sizes for iOS, Android and Windows Phone 8 ?
The only tutorials I could found was about apple and android watch.

Expandable ListView showing all items already expanded/open

$
0
0

Hi,
I am implementing Expandable ListView in xamarin.forms,. But the listview showing all items expanded.
See my code below

 public class MainListView
    {

        private Product _oldProduct;
        public ObservableCollection<Product> Products { get; set; }

        public MainListView()
        {
            Products = new ObservableCollection<Product>
            {
                new Product
                {
                    Title = "Microsoft 650",
                    IsVisible = false
                },
            };
        }

        public void ShoworHiddenProducts(Product product)
        {
            if (_oldProduct == product)
            {
                product.IsVisible = !product.IsVisible;
                UpDateProducts(product);
            }
            else
            {
                if (_oldProduct != null)
                {
                    _oldProduct.IsVisible = false;
                    UpDateProducts(_oldProduct);

                }
                product.IsVisible = true;
                UpDateProducts(product);
            }
            _oldProduct = product;
        }

        private void UpDateProducts(Product product)
        {
            var Index = Products.IndexOf(product);
            Products.Remove(product);
            Products.Insert(Index, product);

        }
    }

 public class Product
    {
        public string Title { get; set; }
        public bool IsVisible { get; set; }
    }

Click event to open listview

    private void ListViewItem_Tabbed(object sender, ItemTappedEventArgs e)
        {
            var product = e.Item as Product;
            var vm = BindingContext as MainListView;
            vm?.ShoworHiddenProducts(product);
        }

This is xaml code

        <ListView Margin="0,0,0,0" 
              VerticalOptions="FillAndExpand"
              ItemTapped="ListViewItem_Tabbed"  
              ItemsSource="{Binding Products}"  
              HasUnevenRows="True"  
              BackgroundColor="Black">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <StackLayout Padding="5">
                            <Label Text="{Binding Title}"  
                               FontSize="Medium"
                               TextColor="Azure"/>
                            <StackLayout IsVisible="{Binding Isvisible}"  
                                    Orientation="Horizontal"  
                                    Margin="0,0,0,0">
                                <Button Text="Place Order"  
                                    WidthRequest="110"  
                                    FontSize="Medium"  
                                    BackgroundColor="Chocolate"  
                                    TextColor="White"/>
                                <Button Text="Details"  
                                    WidthRequest="110"  
                                    FontSize="Medium"  
                                    BackgroundColor="CornflowerBlue"  
                                    TextColor="DarkBlue"/>
                                <Button Text="Edit"  
                                    WidthRequest="110"  
                                    FontSize="Medium"  
                                    BackgroundColor="LightCoral"  
                                    TextColor="Maroon"/>
                            </StackLayout>
                        </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

For this implementation, I have followed below tutorial

https://www.c-sharpcorner.com/article/xamarin-forms-expendable-listview-app/

Viewing all 91519 articles
Browse latest View live


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