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

The project is not compiling showing Could not load file or assembly netstandard version=2.0.0.0.

$
0
0

Hello Developers,

I have a project where I implemented the Autocomplete funtionality.
But The project is not compiling and also not getting build.
Showing Error. How to remove that error ?
Attaching the error image and the project.

  • Sourav

Problem when assigning a DataTable to a ListView ItemsSource

$
0
0

Hi all,

I use Xamarin Forms on Android, but all the code is platform independent.

I want to display the contents of a DataTable in a ListView. The DataTable has 121 rows and 3 columns.

Here is the code:
xaml

<StackLayout>
    <Button x:Name="start" Text="start" Clicked="start_Clicked"></Button>
    <ListView x:Name="lv" SeparatorColor="Black">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <Grid ColumnSpacing="5"  >
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="70"></ColumnDefinition>
                            <ColumnDefinition Width="70"></ColumnDefinition>
                            <ColumnDefinition Width="70"></ColumnDefinition>
                        </Grid.ColumnDefinitions>
                        <Label Grid.Column="0" Text="{Binding ind_cab}" ></Label>
                        <Label Grid.Column="1" Text="{Binding date_modif}" ></Label>
                        <Label Grid.Column="2" Text="{Binding nat_mod}" ></Label>
                    </Grid>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
</StackLayout>

cs

        private async void start_Clicked(object sender, EventArgs e)
        {
    /**************** part outside of the scope**********/
    /**************** beginning of the part inside the scope *************/
            DataTable dt = await ab.LireTable(sql);
            lv.ItemsSource = dt.DefaultView;
            lv.EndRefresh();
    /**************** end of the part inside the scope *************/
        }

The 121 rows are displayed, but the contents of each cell is left blank. A group of 3 errors for each visible row is displayed in the output part of Visual Studio:
[0:] Binding: 'ind_cab' property not found on 'System.Data.DataRowView', target property: 'Xamarin.Forms.Label.Text'
[0:] Binding: 'date_modif' property not found on 'System.Data.DataRowView', target property: 'Xamarin.Forms.Label.Text'
[0:] Binding: 'nat_mod' property not found on 'System.Data.DataRowView', target property: 'Xamarin.Forms.Label.Text'

It behaves as if Xamarin could not get the properties of the DataRowView.

Can anyone help me about that subject ?

Thank you.

Does anybody have sample code for adding a search bar to navigation bar in iOS 11 in addition to Lar

$
0
0

Does anybody have sample code for adding a search bar to navigation bar in iOS 11 in addition to Large Titles for Xamarin Forms?

How to run on UI Thread

$
0
0

Hello,

I'm in trouble to run a portion of code on Ui Thread from shared code. Basically in shared code I download a Json using HttpWebRequest. Parsed Json, the code fails when updating ListView throwing a cross thread exception. This should be fixed running the init og ListView into Ui thread but not found how to do it.

I read "Invoking on the UI Thread" from here: http://developer.xamarin.com/guides/cross-platform/application_fundamentals/building_cross_platform_applications/part_5_-_practical_code_sharing_strategies/

Anyway it seems is not useful.

Thanks

[PRISM] Listview selectedItem in Xaml

$
0
0

Hello everyone,

I started studying the MVVM with Prism and I have some difficulties to open a page from a click on an item.

I spent about ten hours reading the documentation and forum posts but I can't :

https://forums.xamarin.com/discussion/87233/how-to-navigate-each-row-in-listview-to-another-page

http://oxamarin.com/listview-command/

http://www.johankarlsson.net/2015/03/navigation-from-listview.html

https://stackoverflow.com/questions/36600193/how-to-bind-itemtapped-property-of-listview-in-viewmodel-for-navigating-detail-p

Here is my project :

MainPageViewModel

namespace AppPrismV2.ViewModels
{
    public class MainPageViewModel : BindableBase, INavigationAware
    {
        public List<Item> Items { get; set; }

        public MainPageViewModel()
        {
            Items = new List<Item>()
            {
                new Item() { Nom = "George" },
                new Item() { Nom = "Bob" },

            };
        }
}

MainPage Xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
             prism:ViewModelLocator.AutowireViewModel="True"
             x:Class="AppPrismV2.Views.MainPage"
             xmlns:b="clr-namespace:Prism.Behaviors;assembly=Prism.Forms"
             Title="MainPage">
  <StackLayout HorizontalOptions="Center" VerticalOptions="Center">
    <Label Text="{Binding Title}" />

        <ListView ItemsSource="{Binding Items}">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <Label Font="Large" Text="{Binding Nom}" />
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackLayout>
</ContentPage>

Class Item

namespace AppPrismV2
{
    public class Item
    {
        public string Nom { get; set; }
    }
}

Can you explain what I have to implement so that when a click on an item a DetailPage appears ?

put data in my picker after getting it from api

$
0
0

The problem is I want to access an Api and after getting my data from it I should show it inside my picker
This is my code:

        public async Task<bool> GetDoctors() {

            JsonConvert.DefaultSettings = () => new JsonSerializerSettings()
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver(),
                Converters = { new StringEnumConverter() }
            };
            pMSAPI = RestService.For<PMSAPI>("https://pms-beta2.azurewebsites.net");
            try
            {

                var response = await pMSAPI.GetUser();
                doctorInfo = response.Value.Users;

                foreach (DoctorInfo doctor in doctorInfo)
                {
                    doctor_names.Add(doctor.ToString());
                }

Adding Dropdown with Dynamic data [Picker] Also Getting data through WebAPI

$
0
0

Model is here :
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace XamarinWebServices.Models
{
public class CustomerViewModel
{
public int id { get; set; }
public string name { get; set; }
}

// ViewModel:
public class CustomerVM
{
    public CustomerViewModel Data { get; set; }
    public ObservableCollection<CustomerViewModel> CustomerList { get; set; }

    public CustomerVM()
    {
        CustomerList = new ObservableCollection<CustomerViewModel>();
    }
}

}

XAML file for Picker (Dropdown) :
<?xml version="1.0" encoding="utf-8" ?>

</Picker.Items>
</Picker>


And here is the codeBehind with dynamic data through link [Working with Web Api in Xamarin.forms]:

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using XamarinWebServices.Models;

namespace XamarinWebServices
{
public partial class DropDown : ContentPage
{
CustomerVM viewModel;
public DropDown()
{
InitializeComponent();

        viewModel = new CustomerVM();
        BindingContext = viewModel;
    }

     async override protected void OnAppearing()
    {
        base.OnAppearing();
        var json = await GetCustomersAsync();
        List<CustomerVM> customers = JsonConvert.DeserializeObject<List<CustomerVM>>(json);
        foreach (CustomerVM c in customers)
        {
            if (c.Data != null)
            {
                string name = c.Data.name;
                int ID = c.Data.id;

                CustomerViewModel v = new CustomerViewModel();
                v.name = name; v.id = ID;
                CustomerList.Items.Add(name);
                viewModel.CustomerList.Add(v);
            }
        }

    }

    async Task<string> GetCustomersAsync()
    {
        var client = new HttpClient();

        client.BaseAddress = new Uri("http://www.doctorksa.com/webservices/");

        client.DefaultRequestHeaders.Accept.Clear();
        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

        HttpResponseMessage response = await client.GetAsync("country");
        if (response.IsSuccessStatusCode)
        {
            string result = await response.Content.ReadAsStringAsync();
            return result;
        }
        else return response.ReasonPhrase;
    }
    void CustomerList_SelectIndexChanged(object sender, EventArgs args)
    {
        DisplayAlert("Test", "Ok", "Cancle", "Confirm");
    }

}

}

Hope this will help you in working with dropdown and Web API

System.ArgumentException crash in custom UWP FrameRenderer

$
0
0

Hi,

I'm using a custom FrameRenderer in my UWP project to style frames (corner radius and color). When I scroll a bit back and forth, the app crashes with a System.ArgumentException: Value does not fall within the expected range. It's the call to base.OnElementChanged(e); that causes it.

I can of course put that in a try/catch, but then some items in my list will disappear. They return on orientation change of the device, but not after a normal refresh of the FlowListView I'm using.

Any ideas? I'm on Xamarin Forms 2.5.1.444934.

Here's the custom FrameRenderer:

class ExtendedFrameRenderer : FrameRenderer
{
    protected override void OnElementChanged(ElementChangedEventArgs<Frame> e)
    {
        base.OnElementChanged(e);

        if (Control != null)
        {
            var frame = e.NewElement;
            double cornerRadius = frame.CornerRadius;

            Windows.UI.Color frameBG = Windows.UI.Color.FromArgb(
                (byte)(frame.BackgroundColor.A * 255),
                (byte)(frame.BackgroundColor.R * 255),
                (byte)(frame.BackgroundColor.G * 255),
                (byte)(frame.BackgroundColor.B * 255));

            Control.CornerRadius = new Windows.UI.Xaml.CornerRadius(cornerRadius);
            Control.Background = new SolidColorBrush(frameBG);
            frame.BackgroundColor = Xamarin.Forms.Color.Transparent;
        }
    }
}

Full error stack:

System.ArgumentException
  HResult=0x80070057
  Message=Value does not fall within the expected range.
  Source=Windows
  StackTrace:
   at Windows.UI.Xaml.Controls.Border.put_Child(UIElement value)
   at Xamarin.Forms.Platform.UWP.FrameRenderer.PackChild()
   at Xamarin.Forms.Platform.UWP.FrameRenderer.OnElementChanged(ElementChangedEventArgs`1 e)
   at MyApp.UWP.Helpers.ExtendedFrameRenderer.OnElementChanged(ElementChangedEventArgs`1 e) in C:\Users\me\Source\Workspaces\MySol\MyApp\MyApp.UWP\Helpers\ExtendedFrameRenderer.cs:line 26
   at Xamarin.Forms.Platform.UWP.VisualElementRenderer`2.SetElement(VisualElement element)
   at Xamarin.Forms.Platform.UWP.Platform.CreateRenderer(VisualElement element)
   at Xamarin.Forms.Platform.UWP.VisualElementPackager.OnChildAdded(Object sender, ElementEventArgs e)
   at Xamarin.Forms.Platform.UWP.VisualElementPackager.Load()
   at Xamarin.Forms.Platform.UWP.VisualElementRenderer`2.SetElement(VisualElement element)
   at Xamarin.Forms.Platform.UWP.Platform.CreateRenderer(VisualElement element)
   at Xamarin.Forms.Platform.UWP.VisualElementPackager.OnChildAdded(Object sender, ElementEventArgs e)
   at Xamarin.Forms.Platform.UWP.VisualElementPackager.Load()
   at Xamarin.Forms.Platform.UWP.VisualElementRenderer`2.SetElement(VisualElement element)
   at Xamarin.Forms.Platform.UWP.Platform.CreateRenderer(VisualElement element)
   at Xamarin.Forms.Platform.UWP.ViewToRendererConverter.WrapperControl..ctor(View view)
   at Xamarin.Forms.Platform.UWP.ViewToRendererConverter.Convert(Object value, Type targetType, Object parameter, String language)

How do i fade in a page?

$
0
0

Hi guys/girls,

I simply want to fade in a page when it is loaded, how can I do that? I tried it giving the whole page a x:name and then used fadeTo(1, 1000) but no result. Any other ideas please?

View (e.g. status bar) above NavigationBar

$
0
0

Hello,

I'm working on an Xamarin.Forms App for an Android Device (Famoco) which disabled the default status bar (Clock, signal strength, ...) for security reasons. Don't ask me why. Now I'm forced to implement a status bar by myself.

My app makes heavy use of Navigation.Push and Pop and the design approach relies on a NavigationBar.
So ... for now my MainPage inside App.xaml.cs (.NET Standard project) is a NavigationPage ... e.g. MainPage = new NavigationPage(new RootPage());
Within the App I navigate by using Navigation.PushAsync(new OtherPage()); or Navigation.PopAsync()

My question:
How can I put a custom status bar (or any view) application wide on top of the navigation bar ... like this:
(without loosing the ability to navigate using Navigation.Push/Pop)

  • AppFrame
    • StatusBar
    • NavigationBar
    • ContentPage (Changing using NavigationPage)

Sorry, I prepared an image to illustrate my issue but was not allowed (yet) to use it in my first post.

Thanks for any advice
-- Sascha

how to update listitems in child of tabbed page while navigation to page and back again

$
0
0

I have tab page which contains child pages
I make list of items (for example have enable label for each item) i navigate to another page and change items to disabled
when i back again no thing changed untill i run the application again .. i used observable collection for that and prism also INotify property changed another solution i tried to load list again in onAppearing and nothing happens .. how can i solve that ?

 private ObservableCollection<ProductSummaryModel> _lstBestOffers;
        public ObservableCollection<ProductSummaryModel> ListBestOffers
        {
            get { return _lstBestOffers; }
            set { SetProperty(ref _lstBestOffers, value);

            }
        }

and calling this in onAppearing

  var res = await HomeService.GetHomeData();

                if (res != null && res.Data != null)
                {

                    ListBestOffers = new ObservableCollection<ProductSummaryModel>(res.Data.BestOffersSlider.Cards.ToList());
}

Re-installation of APK does not works and through an error "App Not Installed"

$
0
0

I have created a Xamarin Forms .netstandard application with Visual Studio Enterprise 2017 and apk generated from it gets installed for the first time but when i uninstall the application and then try to install the same apk it does not work and through an error that "App not installed". Even if i clean the device before installing it does not works.

I am running
VS 2017 15.8.3
Xamarin.Forms 2.5.0.122203,
Xamarin.Android.Support libraries 2.5.4.0.2,
NETStandard.Library 2.0.3

Even this happens even if I create new application with everything updated it issue prevails.

Please help me if I am doing anything wrong.

How to approach push notifications on Xamarin.Forms project?

$
0
0

So we are working on a pcl project and have our UI set in a page inside the PCL. There is a scenario where our client wants some information to be sent as a push notification. We already have our UI in place and our backend too. We are using Azure to store data and have successfully configured WAMS. However we are scratching head on how to make push notifications work on Android without creating a separate page layout / controls that are android specific.

tl;dr - how do we use the PCL page UI elements to trigger push notifications on an Android device?

I need custom camera like snapchat in xamarin forms.

$
0
0

Please suggest me I stuck here past couple of days.
Thanks in Advance.

Xamarin Forms: Image SourceProperty where does it look into

$
0
0

Hello. I'm new to Cross Platform development with Xamarin Forms. I cane from Unity Game development background so the thing that I'm about to do is the result of my current knowledge.

My question

If I have an image background.jpg downloaded and stored in /data/user/0/com.companyname.appname/files/AssetBundle/background.jpg
When I want to access this using relative path in the Image SourceProperty, what should I put there?
Note that I done this in my .NET Standard Library.

Thanks for help.
Regards.


Problems with Visual studio debugging Xamarin.Forms

$
0
0

I've been having problem with debugging Xamarin.Forms for the last month.

PS: debugging the Web project is fine, this only happens with Xamarin.Forms and Android, not sure if it exists with iOS.

1- When putting the mouse pointer over an object/property when debugging , it is written to the immediate window.
as if I wrote it myself there to see its details. (Redirect all output window text to the Immediate window is UNCHECKED)

2- When putting the mouse pointer over an object/property when debugging , I can't expand the description to see the content/properties of the object,
although there is a plus/expand icon.

3- During debugging: 'Set Next statement' in the right click menu is grayed.

Not sure what caused all this, because everything was fine,
following is what I did lately:
-Updated Visual studio 15.8.0 to 15.8.1 then 15.8.2 then 15.8.3
-Updated Nuget Packages of Xamarin.Forms and all other related packages.

Solution contains:
1- Asp.net Core 2.1 Web project
2- Xamarin Forms 3.1.0.697729
using .Net Standard 2.0.3
3- Xamarin Android Project
4- Xamarin iOS Project

  • Shared project: Settings > Build > Define DEBUG and TRACE are CHECKED.
  • Android project: Settings > Build > Define DEBUG is CHECKED.
  • Visual Studio > Settings > Debugging >
    * Edit and continue is UNCHECKED.
    * Enable Just my code CHECKED
    * Redirect all output window text to the Immediate window is UNCHECKED

Please let me know if there is any missing info.

Write Carousel View DataTemplate in C#

$
0
0

Hi

I'm attempting to implement the new Carousel View control in a Xamarin Forms project. Could someone please give some advice or point me in the right direction on how to write a DataTemplate for the Carousel View in C#. All examples use XAML. Any help will be greatly appreciated.

NavigationPage Title Text color

$
0
0

How do we change the color of the title text in the header on navigation pages?

It always seems to be black for me, and I cannot see any properties which change the text color.

Sorry if this has already been asked, I couldn't find anyone asking this question, but it might just be my goggling skills.

Navigating on Android WebView doesn't always fire

$
0
0

I have a vanilla project. I have setup a simple webview on my page and wired Navigating and Navigated events. When the webview loads its source the first time, Navigating is not called but only Navigated.
This is a simplified example. I use a more complicated one in my real project where the Navigating never gets fired but I always get a Navigated event. Everything works fine on iOS every single time (both events get fired consistently).
Any ideas

<?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:webviewnavigation"
    x:Class="webviewnavigation.MainPage">
    <StackLayout>
        <!-- Place new controls here -->
        <Label
            Text="Welcome to Xamarin.Forms!"
            HorizontalOptions="Center" />
        <WebView
            x:Name="MyWebView"
            HorizontalOptions="FillAndExpand"
            HeightRequest="200"
            Navigated="OnNavigated"
            Navigating="OnNavigating"
            Source="https://www.google.com/" />
    </StackLayout>
</ContentPage>


public partial class MainPage : ContentPage
{
    public MainPage()
    {
        InitializeComponent();
    }

    private void OnNavigating(object sender, WebNavigatingEventArgs args)
    {
        Debug.WriteLine($"OnNavigating {args.Url}");
    }

    private void OnNavigated(object sender, WebNavigatedEventArgs args)
    {
        Debug.WriteLine($"OnNavigated {args.Url}");
    }
}

How do Implement Binding property for ImarkupExtension Class ?

Viewing all 81910 articles
Browse latest View live


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