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

Xamarin.Forms quits unexpectedly on adding element to oberservable collection

$
0
0

Hello, I am using an observalbe collection as a template holder for a Carousel View. When the user gets to the end of the loaded pages, and update is triggered that fetches more data from the server. When I construct a new page template from the data and attempt to add it to the collection, the app just quits suddenly, with no exception being thrown or other indication of what happened.

I tried seeing if I could catch the error in try catch block, but no luck. As soon as I single step into (or over) the Add method (see code below) single step the app just stops immediately returns to the home page.

private ObservableCollection<ResultsScroller> mySource;
public void PopulateResultsPages(List<NominalResult> resultList)
  {
    foreach (var nr in resultList)
    {
      var template = new ResultsScroller();
      template.LoadData(nr);
      try
      {   
        mySource.Add(template);   //  <---------------Failure occurs here.  
      }
       catch (System.Exception e)
     {
     System.Diagnostics.Debug.WriteLine(e.Message);
    }
  }
  lastPosition = mySource.Count - 1;
}

Note I recently updated all my Packages, if that has anything to do with it.


Xamarin Forms ContentPage Xaml template is missing in my latest version of Visual Studio.

$
0
0

I'm using the latest version of Visual Studio 2017(15.5.2). Under the project templates of Xamarin Forms, 'ContentPage Xaml' is missing. I tried reinstalling VS 2017. But no result. Please help.

How to send push notifications in Android mobile.

$
0
0

I have developed an app using Xamarin forms using C#. I am saving some dates in phone data using SQLite. If the date which the user have saved already in SQlite matches today's date, I need to send push notifications. Which approach is best for this scenario for sending notifications and any tutorials avaiable for that?

Thanks in advance.

How to await a DisplayAlert from a page (without async-Button-event)..?

$
0
0

Hi all

This problem follows me, since I work with XF... :-)

On my search-page, I have various search-options (ListViews, SearchBars, etc.).
If the user has searched already and then search once again, I want to ask him, if he want to reset the search-options or not (I have to know this before the page-content is created).
Therefore, I want to display a simple DisplayAlert from the page-definition-code (where the content of the page is defined).
Example:

var AnswerYes = await DisplayAlert("Question","Do you want to reset the search-options?", "Yes", "No");
if (AnswerYes)
 {
  // Reset the search-options
 }
 else
  {
     // Do nothing
  }

The problem is simply, that I have to await the DisplayAlert and the page-definition-code is not async.
If I put the DisplayAlert in a async-function (Task) and call the function without await (the async-function then returns true or false), I got the error-message "A implicit convert from type 'System.Threading.Tasks.Task' in 'bool' is not possible.

So... how to solve this nasty problem?

Or.. is this simply not possible and the only way is, to show the DisplayAlert before the search-page is created?

Thanks for any answer...

HTTP Request: Could not retrieve Picture (status code Forbidden) Xamarin and Drupal

$
0
0

Hello,

I want to display images from DRUPAL 8 but I can not. Images are forbidden.
I want to display them in my Xamarin application.
This is an ANDROID application, the site is in HTTPS and I use DRUPAL 8.

You will find my project below

**** reprensent my domain.

[0:] HTTP Request: Could not retrieve ****/json/S8-constructeurs-de-luxe-et-le-champion-des-reseaux-sociaux-est-lamborghini-383536.jpg, status code Forbidden
[0:] ImageLoaderSourceHandler: Could not retrieve image or image data was invalid: Uri: ****json/S8-constructeurs-de-luxe-et-le-champion-des-reseaux-sociaux-est-lamborghini-383536.jpg


using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using Xamarin.Forms;

namespace RestApiAPp
{
public partial class MainPage
{
private const string Url = "****/jsontest3"; //This url is a free public api intended for demos
private readonly HttpClient _client = new HttpClient(); //Creating a new instance of HttpClient. (Microsoft.Net.Http)
private ObservableCollection _posts; //Refreshing the state of the UI in realtime when updating the ListView's Collection

    public MainPage()
    {
        InitializeComponent();          

        _client.DefaultRequestHeaders.TryAddWithoutValidation("Accept", "application/vnd.api+json");           
        _client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36");         

    }

    protected override async void OnAppearing()
    {
        string content = await _client.GetStringAsync(Url); //Sends a GET request to the specified Uri and returns the response body as a string in an asynchronous operation
        List<Post> posts = JsonConvert.DeserializeObject<List<Post>>(content); //Deserializes or converts JSON String into a collection of Post
        _posts = new ObservableCollection<Post>(posts); //Converting the List to ObservalbleCollection of Post
        MyListView.ItemsSource = _posts; //Assigning the ObservableCollection to MyListView in the XAML of this file
        base.OnAppearing();
     }


}

}


using System.ComponentModel;
using System.Runtime.CompilerServices;
using RestApiAPp.Annotations;

namespace RestApiAPp
{
internal class Post : INotifyPropertyChanged
{
public int Id { get; set; }

    private string _title;
    public string Title
    {
        get => _title;
        set
        {
            _title = value;
            OnPropertyChanged(); //This notifies the View or ViewModel that the value that a property in the Model has changed and the View needs to be updated.
        }
    }

    private string _field_comp_picture;
    public string Field_comp_picture
    {
        get => _field_comp_picture;
        set
        {
            _field_comp_picture = value;
            OnPropertyChanged(); //This notifies the View or ViewModel that the value that a property in the Model has changed and the View needs to be updated.
        }
    }         

    //This is how you create your OnPropertyChanged() method
    public event PropertyChangedEventHandler PropertyChanged;

    [NotifyPropertyChangedInvocator]
    protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }

}

}

Can you help me ?
I remain at your disposal, if you have questions!

Best Regards,
Kévin

Recreating this effect in Xamarin.forms

Anybody knows xaml spy?

$
0
0

If i install the package in the visual studio 2017, will have some issue or not. My version is a evaluate version, but if i install via NuGet will i have problem? It seems to work with visual studio 2015 only.

Problem running app on Xamarin Live Player with .NET 2017

$
0
0

Hi,

I'm trying to build a simple app with Xamarin and .NET 2017 Community Edition but I'm having some problems with the Live Player.

When I create an empty app or a "Master Detail" without Azure, I can run either one of these on the Emulator or Live Player directly on my phone but when I create an app based on the template "Master Detail" and select "Include Azure Mobile" but do not go through with the Azure set up.

I can compile the app with a few warning and I can run it without any problems on the emulator: Android_Accelerated_x86_Nougat_(Android 7.1 - API 25) .

When I select my Samsung SM-G955F Player (Android 7.0 - API 24) which is a Samsung S8+, and compile the project, I get a number of warnings:

Severity Code Description Project File Line Suppression State
Warning NU1608 Detected package version outside of dependency constraint: Xamarin.Android.Support.CustomTabs 23.3.0 requires Xamarin.Android.Support.v4 (= 23.3.0) but version Xamarin.Android.Support.v4 25.4.0.2 was resolved.

Severity Code Description Project File Line Suppression State
Warning The $(TargetFrameworkVersion) for FormsViewGroup.dll (vv8.0) is greater than the $(TargetFrameworkVersion) for your project (v7.0). You need to increase the $(TargetFrameworkVersion) for your project. myproject.Android C:\Users\Thierry\source\repos\myproject\myproject\myproject.Android\myproject.Android.csproj

Severity Code Description Project File Line Suppression State
Warning The $(TargetFrameworkVersion) for Xamarin.Forms.Platform.dll (vv8.0) is greater than the $(TargetFrameworkVersion) for your project (v7.0). You need to increase the $(TargetFrameworkVersion) for your project. myproject.Android C:\Users\Thierry\source\repos\myproject\myproject\myproject.Android\myproject.Android.csproj

**Severity Code Description Project File Line Suppression State
**Warning The $(TargetFrameworkVersion) for Xamarin.Forms.Platform.Android.dll (vv8.0) is greater than the $(TargetFrameworkVersion) for your project (v7.0). You need to increase the $(TargetFrameworkVersion) for your project. myproject.Android C:\Users\Thierry\source\repos\myproject\myproject\myproject.Android\myproject.Android.csproj

Severity Code Description Project File Line Suppression State
Warning Found conflicts between different versions of the same dependent assembly. In Visual Studio, double-click this warning (or select it and press Enter) to fix the conflicts; otherwise, add the following binding redirects to the "runtime" node in the application configuration file: myproject.MobileAppService

**Severity Code Description Project File Line Suppression State
Warning NU1608 Detected package version outside of dependency constraint: Xamarin.Android.Support.CustomTabs 23.3.0 requires Xamarin.Android.Support.v4 (= 23.3.0) but version Xamarin.Android.Support.v4 25.4.0.2 was resolved.

but it does compile successfully but I cannot get it to run successfully on my phone as it is throwing various errors. The error are listed below but it pretty much seems that none of my libraries are somehow referenced to the project which is not the case.

Severity Code Description Project File Line Suppression State
Error Dependent project myproject.csproj failed to build, using old version. 1
Error The type or namespace name 'App' could not be found (are you missing a using directive or an assembly reference?)
Error The type or namespace name 'WindowsAzure' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
Error The type or namespace name 'IMobileServiceSyncTable<>' could not be found (are you missing a using directive or an assembly reference?)
Error The type or namespace name 'MobileServicePushFailedException' could not be found (are you missing a using directive or an assembly reference?)
Error The type or namespace name 'MobileServiceJsonSerializerSettings' could not be found (are you missing a using directive or an assembly reference?)
Error The name 'MobileServiceTableOperationKind' does not exist in the current context
Error The type or namespace name 'MobileServiceSQLiteStore' could not be found (are you missing a using directive or an assembly reference?)
Error The type or namespace name 'MobileServiceClient' could not be found (are you missing a using directive or an assembly reference?)
Error The type or namespace name 'MobileServiceSyncHandler' could not be found (are you missing a using directive or an assembly reference?)
Error The name 'MobileServiceClient' does not exist in the current context
Error The type or namespace name 'RelayCommand' could not be found (are you missing a using directive or an assembly reference?)
Error The type or namespace name 'PreferredConstructorAttribute' could not be found (are you missing a using directive or an assembly reference?)
Error The name 'Set' does not exist in the current context
Error The type or namespace name 'GalaSoft' could not be found (are you missing a using directive or an assembly reference?)
Error The type or namespace name 'PreferredConstructor' could not be found (are you missing a using directive or an assembly reference?)
Error The type or namespace name 'ViewModelBase' could not be found (are you missing a using directive or an assembly reference?)
Error The name 'SimpleIoc' does not exist in the current context

I have remove paths from the errors for simplicity sake.

You might have noticed that I've included a reference to MVVMLight as this is what I'm used to and it is the .NET standard version (alpha)

Does anyone have any ideas on how I can resolve this?

Thanks.

Thierry


How do use setters in App.xaml to bind values to a custom class?

$
0
0

I have a custom class with custom properties that need to be retrieved. This works in the app.xaml:

<cols:List x:Key="SchemaModifications" x:TypeArguments="SAL:SchemaModification">
    <SAL:SchemaModification ApplicationVersion="7.7"  />
</cols:List>

but no matter what I try I can't seem to use a setter. Any tips?

Any chance to have a Xamarin.Forms.ListView / TableView to implement a search facility to filter the

$
0
0

Any chance to have a Xamarin.Forms.ListView / TableView to implement a search facility to filter the list items?

Issues with JSON serialization in DEBUG and RELEASE mode

$
0
0

Hi

I am writing an app that de-serializes a JSON string into an object. The class that defines this object is inside a Shared (Portable) library and the reference to it is correctly added in the Xamarin.Forms app. The deserialization process works perfectly when the app is running in DEBUG mode. However, when I run it in RELEASE mode, there is an error that comes up :

"Unable to find a constructor to use for the type TypeName. A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute."

The class did not have a constructor. So, I added one that actually does not do anything and have no argument. The error still occured. I added the JsonConstructor attribute and still the error occurs. I signed the Shared Portable project, but it still occurs. It is happening only in RELEASE mode, not in DEBUG mode.

Any assistance you may provide will be much appreciated.

Regards

Terence

Centering in Xamarin.Form's RelativeLayout vs Android's RelativeLayout

$
0
0

When programming in Android, if I have to center something, this is all I need is the below line in the XML:
android:CenterInParent="true"

If there an equivalent way to center an object in XAML?

Thanks!

ListView set Hasunevenrows="true" not working.

storyboard as lunch screen

$
0
0

Hi,

I have no idea how to create a story board and set it as lunch screen (I am targeting iPhone X, so I am forced to use story board)
I have tried to create a blank storyboard, then I have put (view controller) then I put an Image view inside the controller.
I have checked (use size class, can be launch screen) options and set the storyboard as lunch screen in info.plist

what am I doing wrong?

Event To Comand in Xamarin Forms project using .NET Standards

$
0
0

Hi,

I was wondering if there was an equivalent to the MVVMLight EventToCommand available when using a Xamarin Forms project that's using .NET Standards?

I found the following article: h t t p : / / blog.xamarin.com / turn-events-into-commands-with-behaviors, which basically shows you how to create a ListView behaviour to handle such a requirement but I don't like the idea as I would have to create a behaviour for every control type that require the "EventToCommand".

In the past, I would have used something similar to the below with the Microsoft Interactivity and MVVMLight libraries:

<i:Interaction.Triggers>



</i:Interaction.Triggers>

or with arguments

<i:Interaction.Triggers>



</i:Interaction.Triggers>

That's just 2 examples but I use this mechanism on many controls such as ListViews, Grids, TreeViews, etc... and while I know many of these won't be used in a Xamarin Forms project, I'd still prefer this scenario over the one where I'd have to create a Behaviour for each control and their corresponding events.

I'd like to know if there is an equivalent in Xamarin forms to this feature or if you know how to use this with the new mvvmlight .net standard library

Many thanks.


Xamarin Forms Android Build issues like already defined with Incompatible format (APT0000)

$
0
0

I am experiencing the issue in building Xamarin.Android project with Xamarin forms application, recently updated the packages. The applications is working fine in iOS but not working in Android.
When I am trying to build
the application its throwing the errors like already defined with incompatible format (APT0000).

Please find the below as same screen shot that I have build errors

Access list data when click of a Button inside listview-viewcell

$
0
0

Hi,

I have a button inside listview-viewcell. For the button, I am using clicked event. So on click of the button, I need the details of the selected list item like the first name, email etc. I tried like following:

Xaml code:

      <ListView x:Name="MyDirectories"
                      HasUnevenRows="True">
                 <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <ViewCell.View>
                                     <Button
                                            BorderRadius="25"
                                            HeightRequest="40"
                                            WidthRequest="150"
                                            TextColor="White"
                                            HorizontalOptions="CenterAndExpand"
                                            Font="Bold,15"
                                            Margin="0,0,0,5"
                                            BackgroundColor="#004F7E" 
                                            Clicked="MoreDetails"
                                            Text="More Details"/>
                                </StackLayout>
                            </ViewCell.View>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
             </ListView>

Xaml.cs code:

           public class MyListItemEventArgs : EventArgs
            {
                public UserProfileTO MyItem { get; set; }
                public MyListItemEventArgs(UserProfileTO item)
                {
                    this.MyItem = item;
                }
            }

           public void MoreDetails(Object sender, MyListItemEventArgs args)
            {
                 var item = args.MyItem;
                if (item != null)
                {
                    Debug.WriteLine("Firstname:>"+item.firstName);
                }
           }

This didn't work, anybody please suggest any other solution :)
Thanks in advance :)

Crashlytics for xamarin.forms

$
0
0

I want to integrate crashlytics for xamarin.iOS and xamarin.droid app. Which platform should I use to monitor the crashes and how can integrate it in Visual Studio 2017.

ListView on iOS with hasunevenrows='true' are bugged, works fine on Android

$
0
0

Hi, i've got issue using HasUnevenRows="True" and infinitescroll loading on iOS. When items are added it scroll to some position on top, on android works perfectly. I can't find a solution.
Thats'my view code:

public NewsViewModel()
        {
            ListaNews = new InfiniteScrollCollection<News>
            {
                OnLoadMore = async () =>
                {
                    IsLoading = true;
                    var page = ListaNews.Count / PageSize;
                    var items = await App.RestService.GetListaNewsAsync(page + 1, PageSize);
                    IsLoading = false;
                    return items;
                }
            };
            ListaNews.LoadMoreAsync();
        }

That's my Xaml:

<ListView ItemsSource="{Binding ListaNews}"  SeparatorVisibility="None" HasUnevenRows="true" >
            <ListView.Behaviors>
                <scroll:InfiniteScrollBehavior />
            </ListView.Behaviors>
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <customcontrol:Card  HasShadow="True">
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"></RowDefinition>
                                    <RowDefinition Height="Auto"></RowDefinition>
                                    <RowDefinition Height="Auto"></RowDefinition>
                                    <RowDefinition Height="Auto"></RowDefinition>
                                </Grid.RowDefinitions>
                                <Image Grid.Row="0" Source="{Binding SummaryImageBase64, Converter={converter:Base64ImageSourceConverter} }" IsVisible="{Binding SummaryImageBase64, Converter={converter:Base64ImageSourceVisibleConverter}}" HeightRequest="250" Aspect="AspectFit">
                                </Image>
                                <Label Grid.Row="1" Text="{Binding Data, Converter={converter:DateTimeToShortDateStringConverter}}"/>
                                <Label Grid.Row="2" Text="{Binding Title}" FontSize="Large"/>
                                <customcontrol:HtmlLabel Grid.Row="3" Text="{Binding Summary}"/>
                            </Grid>
                        </customcontrol:Card>
                        </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
            <ListView.Footer>
                <Grid Padding="4" IsVisible="{Binding IsLoading}">
                    <!--set the footer to have a zero height when invisible-->
                    <Grid.Triggers>
                        <Trigger TargetType="Grid" Property="IsVisible" Value="False">
                            <Setter Property="HeightRequest" Value="0" />
                        </Trigger>
                    </Grid.Triggers>
                    <!--the loading content-->
                    <ActivityIndicator
                    IsRunning="true"
                    Color="Black"
                    WidthRequest="20"
                    HeightRequest="20"/>
                </Grid>
            </ListView.Footer>
        </ListView>

Formatting lost when using ListViewCachingStrategy.RecycleElement with FormattedString

$
0
0

I'm attempting to move a ListView in my app to use the RecycleElement ListViewCachingStrategy. The DataTemplate for the list view items has a Label with the Text property bound a property in the view model that returns a FormattedString, in order to make some parts of the text appear bold. This works correctly with RetainElement, but with RecycleElement the formatting appears correctly initially, but after scrolling through some items in the list it is lost and the text appears without any of the formatting. Can anyone help? Is this a limitation of this caching strategy or possibly a bug?

Viewing all 58056 articles
Browse latest View live


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