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

DependencyService: System.MissingMethodException: Default constructor not found for [Interface]

$
0
0

I am receiving this error when using the Dependency Service on a Xamarin.Forms PCL. I have seen answers to this error that involve iOS and the Linker.
However, I am running this on Android and the Linker is off. Debug mode as well.

The constructor it is telling me it cannot find the default constructor for the Interface in the PCL.

I thought it may have been an issue with some renaming I did (I used refactor tool and made sure all necessary changes were being made) so I deleted those folders/files and remade them. Still nothing :(

Here is my related code.

Interface:
`namespace Enchantum.Functions
{
public interface PaymentProcessor
{

    void setUpCard(String cardNumber,
        int expirationMonth,
        int expirationYear,
        String CVC);

    Task cardTokenizer();

    void backendCardCharge();

}`

Android:
`[assembly: Xamarin.Forms.Dependency(typeof(PaymentProcessor_Android))]

namespace Enchantum.Droid.Functions_Android
{
class PaymentProcessor_Android : PaymentProcessor
{
public PaymentProcessor_Android() { }

    private Card mCard;
    private Token mToken;

    public void setUpCard(String cardNumber, int expirationMonth,
        int expirationYear, String cvcCode)
    {
        Card card = new Card
        {
            Number = cardNumber,
            ExpiryMonth = expirationMonth,
            ExpiryYear = expirationYear,
            CVC = cvcCode
        };

        mCard = card;
    }

    public async Task cardTokenizer()
    {
        mToken = await StripeClient.CreateToken(mCard);
    }

    /*TODO: 
     * */

    public void backendCardCharge()
    {
        throw new NotImplementedException();
    }

`

iOS:
`[assembly: Xamarin.Forms.Dependency(typeof(PaymentProcessor_iOS))]

namespace Enchantum.iOS.Functions_iOS
{
class PaymentProcessor_iOS : PaymentProcessor
{
public PaymentProcessor_iOS() { }

    private Card mCard;
    private Token mToken;

    public void setUpCard(String cardNumber, int expirationMonth,
        int expirationYear, String cvcCode)
    {
        Card card = new Card
        {
            Number = cardNumber,
            ExpiryMonth = expirationMonth,
            ExpiryYear = expirationYear,
            CVC = cvcCode
        };

        mCard = card;

    }

    public async Task cardTokenizer()
    {
        mToken = await StripeClient.CreateToken(mCard);
    }

    /*TODO: 
    public void backendCardCharge()
    {
        throw new NotImplementedException();
    }




}`

Implementation in a Xamarin.Form Content Page:
DependencyService.Get<PaymentProcessor>().setUpCard( cardNumber, expirationMonth, expirationYear, CVC);

My error, again : "System.MissingMethodException: Default constructor not found for type Enchantum.Functions.PaymentProcessor"

P.S. Pardon my incorrect naming convention for the Interface.


Xamarin map free or paid

How to do design Mobile screens on the basis mobile Screen Sizes?

$
0
0

plz give solution ..................
Thank U!

Problem with Binding and IsVisible

$
0
0

Hi there,

I am (obviously, regarding the question) new to this, so thanks in advance for any help! As I am trying my current best on this for hours now, I hope, someone can accelerate my learning curve :)

So, I have my XAML MainPage:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="cant post links"
             xmlns:x="cant post links"
             xmlns:local="clr-namespace:App.ViewModels"
             x:Class="App.ViewModels.MainPage">

    <ContentPage.BindingContext>
        <local:User/>
    </ContentPage.BindingContext>

    <StackLayout>
        <Label Text="Test"/>
        <ListView ItemsSource="{Binding Changes}"
                  x:Name="ChangesList"
                  HasUnevenRows="True"
                  Margin="40,80"
                  ItemTapped="ListView_ItemTapped">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <StackLayout>
                            <Label Text="{Binding Name}"/>
                            <Button Text="Details"
                                    IsVisible="{Binding IsVisible}"/>
                        </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
        <Button Text="Press to add" x:Name="addItem" Clicked="addItem_Clicked"/>
    </StackLayout>

</ContentPage>

I have a datamodel with the correponding attributes behind. When I leave the MainPage class constructor like the following:

public MainPage()
{
    InitializeComponent();
}

I see no list items.

So, first Question: I thought, based on the bindings, the app would automatically generate a User instance and assign it to the list? As I can see with the debugger, a User instance actually is generated and also assigned to the BindingContext, but the ChangesList.ItemsSource remains null.

Therefore, I changed the code of the constructor:

public MainPage()
        {
            InitializeComponent();
            var bc = BindingContext;
            var list = ChangesList.ItemsSource;
            ChangesList.ItemsSource = (bc as User).Changes;
        }

This lets me see a list with items when I compile and run the app. Also, I can add new items to the list via the code behind the 'addItem' Button. However: Nothing happens, when I tap an item. The code looks like follows:

        private void ListView_ItemTapped(object sender, ItemTappedEventArgs e)
        {
            var change = e.Item as Change;
            change.IsVisible = !change.IsVisible;
        }

and the Data methods look as follows:

        public bool IsVisible
        {
            get
            {
                return isVisible;
            }
            set
            {
                isVisible = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Change-IsVisible"));
            }
        }

Therefore the second question: Why does the Button not change its visibility status and become visible?

Thank you very much in advance!
Wolf

ListView not displaying in Xamarin.Forms/macOS project

$
0
0

I have a Xamarin.Forms macOS project with a ListView that has IsGroupingEnabled=true and can't get it to display when I run the app.

The ListView displays with data in the Preview window and on the iOS simulator but when running the mac project it just shows a blank white screen. ListViews do work on macOS right? Am I missing something else? Thanks!

<?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:IntegratorSimpleXF"
    x:Class="IntegratorSimpleXF.MainPage">

    <ListView 
        x:Name="PresenceListView" 
        BackgroundColor="White" 
        CachingStrategy="RecycleElement"  
        IsGroupingEnabled="true" 
        GroupDisplayBinding="{Binding Key}">

        <ListView.GroupHeaderTemplate>
            <DataTemplate>
                <ViewCell>
                    <ContentView Padding="5,0,0,0">
                        <Label Text="{Binding Key}" VerticalOptions="Center"/>
                    </ContentView>
              </ViewCell>
            </DataTemplate>
        </ListView.GroupHeaderTemplate>

        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell Height="40">

                    <StackLayout Orientation="Horizontal" HorizontalOptions="FillAndExpand" BackgroundColor="White">                  

                        <StackLayout Orientation="Vertical" WidthRequest="160" Margin="10,0,0,0" Spacing="0" HorizontalOptions="StartAndExpand">
                            <Label TextColor="Black" LineBreakMode="TailTruncation" HorizontalOptions="StartAndExpand" Text="{Binding FullName}" Margin="15,3,0,0" FontSize="Small" />
                            <Label TextColor="Blue" Text="{Binding PhoneExtension}" Margin="15,0,0,2" FontSize="Small" />
                        </StackLayout>

                        <StackLayout Orientation="Horizontal" HeightRequest="20" WidthRequest="10" VerticalOptions="Start" HorizontalOptions="CenterAndExpand" Margin="10,3,0,0" >
                            <Image HorizontalOptions="Center" HeightRequest="10" WidthRequest="10" IsVisible="{Binding IsAvailable}" Source="green_checkmark" Margin="0,0,0,2" />
                            <Frame IsVisible="{Binding IsNotAvailable}" BackgroundColor="Transparent" HeightRequest="10" WidthRequest="10"/>
                        </StackLayout>

                        <Label Text="{Binding PersonStatus}" HeightRequest="20" WidthRequest="100" HorizontalTextAlignment="Start" TextColor="Black" FontSize="Small" Margin="0,3,3,0" />                       
                    </StackLayout>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

</ContentPage>

Xamarin.Forms dll Issues

$
0
0

Hi all, I'm Xamarin Android Developer and just a beginner in Xamarin.Forms. I have created a blank project in Xamarin.Forms and trying to run it on my device but it's showing me "xamarin.forms.build.tasks.gettasksabi could not be loaded" error. Googling the problem does not provide any definitive fix.

Nugget package Xamarin.Forms is already installed and don't know why it's showing me like that.

Any help is appreciated.

How to make master detail page in which sections are there.?

$
0
0
This Is the image I want to create..i got only one separator using box view..dont get another separator.how can I solve this and get the same page which is in image

Forms9Patch: Simplify multi-device image management in your PCL Xamarin.Forms mobile apps

$
0
0

Announcement of Form9Patch

Xamarin Forms is great for developing apps on Android and iOS but it is missing two important tools for developers: scalable images and PCL multi-screen image management. Android developers use NinePatch bitmaps and the drawable directory naming convention for this purpose. Likewise, iOS developers use ResizeableImageWithCapInsets and the @2x, @3x, @4x file naming convention for this purpose.

Forms 9 Patch enhances Xamarin Forms to enable multi-resolution / multi-screen image management to PCL apps for iOS and Android.

What is it?

Simply stated, Forms9Patch is two separate elements (Image and ImageSource) which are multi-screen / multi-resolution extensions of their Xamarin Forms counterparts.

Forms9Patch.ImageSource

Xamarin Forms provides native iOS and Android multi-screen image management (described here). This requires storing your iOS images using the native iOS schema and storing your Android images using the Android schema. In other words, duplicative efforts to get the same results on both Android and iOS. Forms9Patch.ImageSource extends Xamarin.Forms.ImageSource capabilities to bring multi-screen image management to your PCL assemblies - so you only have to generate and configure your app's image resources once. Forms9Patch.ImageSource is a cross-platform implementation to sourcing multi-screen images in Xamarin Forms PCL apps as embedded resources.

Forms9Patch.Image

Forms9Patch.Image compliments Xamarin.Forms.Image to provide Xamarin Forms with a scaleable image element. Scalable images are images that fill their parent view by stretching in designated regions. The source image for the Forms9Patch.Image element can be specified either as a Forms9Patch.ImageSource or a Xamarin.Forms.ImageSource. Supported file formats are NinePatch (.9.png), .png, .jpg, .jpeg, .gif, .bmp, and .bmpf.

Example code

After adding the file bubble.9.png to your PCL project assembly as an EmbeddedResource, you can display it using something like the following:

var bubbleImage = new Forms9Patch.Image () {
    Source = ImageSource.FromResource("MyDemoApp.Resources.bubble.9.png"),
    HeightRequest = 110,
}
var label = new label () {
    Text = "Forms9Path NinePatch Image",
    HorizontalOptions = LayoutOptions.Center,
}

Example XAML

In Xamarin Forms, access to embedded resources from XAML requires some additional work. Unfortunately, Forms9Patch is no different. As with Xamarin Forms, you will need (in the same assembly as your embedded resource images) a simple custom XAML markup extension to load images using their ResourceID.

    [ContentProperty ("Source")]
    public class ImageMultiResourceExtension : IMarkupExtension
    {
        public string Source { get; set; }

        public object ProvideValue (IServiceProvider serviceProvider)
        {
            if (Source == null)
                return null;

            // Do your translation lookup here, using whatever method you require
            var imageSource = Forms9Patch.ImageSource.FromMultiResource(Source);

            return imageSource;
        }
    }

Once you have the above, you can load your embedded resource images as shown in the below example. Be sure to add a namespace for the assembly that contains both your MarkupExtension and your EmbeddedResources (local in the below example).

<?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:MyXamlDemo;assembly=MyXamlDemo"
    x:Class="MyXamlDemo.MyPage"
    Padding="5, 20, 5, 5">
    <ScrollView>
        <ScrollView.Content>
            <StackLayout>
            <Label Text="Xamarin.Image"/>
            <Image Source="{local:ImageMultiResource Forms9PatchDemo.Resources.image}"/>
            </StackLayout>
        </ScrollView.Content>
    </ScrollView>
</ContentPage>

Where to learn more

Project page: http://Forms9Patch.com
Nuget page: https://www.nuget.org/packages/Forms9Patch/0.9.1
Demo app repository: https://github.com/baskren/Forms9PatchDemo


MVVM viewmodel deselect listview item

$
0
0

Is there a way to deselect a listview item in a viewmodel without having to do it in the xaml code behind?

How to pick a file from Device(iOS, Android)

$
0
0

Hi All,

I have deployed app using Xamarin Form.
I have some requirement to pick a file( images, documents, videos except .zip file) from device.
Can you please suggest? It is very urgent for me.

X.Forms Android Button OnPress Visual Bug

$
0
0

Hey guys,

I'm really frustrated and require some help from you. I'm not really new at Xamarin, but some things won't get in my brain. Maybe I haven't understood the entire logic so far.

But, my problem is: I've been adding a Button to the content page and all were working fine. So, I had to change the background color and now it's messed up! When I click the button, it shows WHILE the press event is invoked, a small visible rectangle with the 0.25 scale of the entire button on the top left of the button.

Can someone help me? I've made a screenshot WHILE PRESSING THE BUTTON here:

Note: BEFORE changing the background color, all has been working fine. AFTER setting the background color, the color gets changed well and is correct but the PRESS/CLICK/ACTIVE state of the button shows a small - unrequired - rectangle on the top left of the button.

Thankful for every answer.

Kind regards,
Dominik G.

Grid row/cell won't size properly with custom renderer label (trunctate)

$
0
0

Hello everyone,

I'm having some trouble getting the height of a grid row to correctly resize to the text label fitted within.
The label itself uses a custom renderer to ellipse the text, if it takes up more than two lines.
But it seems as though the height of the grid row still spaces to the full string of the text.
Secondly, the correct size is apparently "recalculated" and fixes itself after scrolling further down the list view.

Additional:
I use a datatemplateselector to pick the datatemplate for the listview entry.

Is there anyway for me to force this "recalculation" or just make it scale correctly in the first go?

I'm not allowed to post pictures sadly, not sure how to show you guys the problem, I have both pictures and a gif of it

Code for the renderer label

protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
        {
            base.OnElementChanged(e);

            if (Control != null)
            {
                Control.LayoutChange += (s, args) =>
                {
                    var baseLabel = (MultiLineLabel)this.Element;

                    Control.SetMinLines(0);
                    Control.Ellipsize = TextUtils.TruncateAt.End;
                    Control.SetMaxLines(baseLabel.Lines);
                };
            }

        }

The grid that holds the multiline label

<Grid x:Name="detailGrid">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" x:Name="detailLabelRow"/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>

                    <CustomRenderers:MultiLineLabel x:Name="detailLabel"
                                                HorizontalOptions="StartAndExpand"
                                                FontSize="Small"
                                                TextColor="Red"
                                                Lines="2"/>

                </Grid>

Any help would be greatly appreciated!
Thanks!

Plugin.Multilingual

$
0
0

Hola
I have created the AppResources.Rex in my project, for iOS and Android and the resx file don´t show the table to fill... ?¿?
show this

<?xml version="1.0" encoding="utf-8"?>
<root>
    <resheader name="resmimetype">
        <value>text/microsoft-resx</value>
    </resheader>
    <resheader name="version">
        <value>2.0</value>
    </resheader>
    <resheader name="reader">
        <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
    </resheader>
    <resheader name="writer">
        <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
    </resheader>
</root>

How to create bindable event handler in custom view cell

$
0
0

Hi,
I have created native ViewCellRenderer for view cell that is being used in list view For UWP by following Microsoft article Customizing a ViewCell.
The article explains how to create bindable properties for a view cell that can be displayed using the native controls. What I want is to be able to create a bindable event handler so that I can bind this event with native UWP code say Tapped event of Textbock.

Example- On the tapped event of Textblock 'Name' i want to navigate to some another page. The navigation logic is written inside the view model for the page where I am using the list view with custom view cell. How can I create a bindable event handler in custom view cell so that I could bind it with the Tapped event of native code.

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>


xamarin form android gif

$
0
0

hello, I am trying to insert a gif in my splashscreen. I tried the component josemango gifimageview, but does not work for me.

my splash screen:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <color android:color="@color/splashscreencolor"/> </item> <item> <bitmap android:src="@drawable/screen" android:tileMode="disabled" android:gravity="center"/> </item> <item> <bitmap android:src="@drawable/logo_wuthink" android:tileMode="disabled" android:gravity="center"/> </item> <item> <com.felipecsl.gifimageview.library.GifImageView android:id="@+id/gifImageView" android:layout_gravity="center" android:scaleType="fitCenter" android:layout_width="match_parent" android:layout_height="match_parent" /> </item> </layer-list>
My code on create on SplashScreen:

` private void LoadGifImage()
{
var gifImageView = FindViewById(Resource.Id.gifImageView);
var assets1 = Assets.List(string.Empty);
string content;

        if (assets1.Any())

        {
            var videoFilename = assets1.FirstOrDefault(a => a.EndsWith(".gif"));

            if (!string.IsNullOrWhiteSpace(videoFilename))

            {
                var fileDescriptor = Assets.OpenFd(videoFilename);

                using (var input = this.Assets.Open(videoFilename, Access.Streaming))
                {
                    byte[] buffer;
                    using (Stream s = input)
                    {
                        long length = fileDescriptor.Length;
                        buffer = new byte[length];
                        s.Read(buffer, 0, (int)length);

                        gifImageView.SetBytes(buffer);
                        gifImageView.StartAnimation();
                    }
                }

            }

        }
        gifImageView.Background = new ColorDrawable(Color.Transparent);
    }`

my gif i have insert into directory asset.

But I get this error:

Android.Content.Res.Resources+NotFoundException: File res/drawable/splashscreen.xml from drawable resource ID #0x7f0200ea

Correct XAML pattern to bind element to BindingContext property ('x:Name' binds to page not context)

$
0
0

Hi, I'm new to Xamarin, but I've already built a few pages and have got most of the binding working flawlessly.
I am, however, having an issue figuring out the proper way to bind an element in XAML (a Map to be precise) to a child property of the BindingContext (a ViewModel). I see that the "x:Name" attribute will bind it to a property of the page class, but not the context. All the other binding examples affect values of an element, but not the element object itself.
Is there a way to do this cleanly, or do I have to do what I'm doing now where the page class passes the element (Map) along into the ViewContext manually at startup?

Xamarin.Forms on iOS is not showing NavigationBar at the first page

$
0
0

Hello guys,

i am struggleling since a few hours. I do an Xamarin.Forms app targeting UWP and iOS.
On UWP everything works good. But on iOS the first page is not showing up the NavigationBar. I explicitly set

NavigationPage.SetHasNavigationBar(this, true);

I also set it in the xaml. I wrapped the page within a NavigationPage. I navigated through Prism.Forms as well as creating it by hand:

Application.Current.MainPage = new NavigationPage(new MyPage() {Title="bla"}) { Title ="blablabla"};
I'm using the most current Xamarin.Forms Version: 3.1.0.697729. Is there a bug?

best regards,
Chris

Xamarin.Forms compilation error: Could not load assembly 'Xamarin.Android.Support.Compat, Version=1.

$
0
0

Error:
Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'Xamarin.Android.Support.Compat, Version=1.0.0.0, Culture=neutral, PublicKeyToken='. Perhaps it doesn't exist in the Mono for Android profile?
File name: 'Xamarin.Android.Support.Compat.dll'

  • VS2017
  • Xamarin.Forms 2.5.1 installed
  • Xamarin.Android.support.Compat v25.4.0.2 installed

Anyone?

Connect to a Rest web service

$
0
0

Hello,
How to connect to a rest web service from a Xamarin application ?
Thx

Viewing all 91519 articles
Browse latest View live


Latest Images

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