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

HorizontalListView inside custom ViewCell of ListView

$
0
0

Hello

My app contains ListView that has custom rendered ViewCells. Each of ViewCell contains HorizontalScrollView with simple content.
When I scroll HorizontalScrollView and immediately scroll ListView vertically, then magic happens.

Newly rendered HorizontalScrollView has scroll position X of last destroyed HorizontalScrollView..

How to prevent this? Is this bug? Why is this happening?

I attach simple project with that problem.
Steps to reproduce: Start Android Project -> Scroll first row horizontally -> scroll listView vertically -> Bug! Newly created row has scroll position X of the first row.


Can't find interface for dependency injection in iOS

$
0
0

Hi,

This, I hope is easy. I am using dependency injection to find the file path for both file storage and for SQLite. It works great on Android bu on iOS it says it can't find the interface. Is this known? Am I doing something stupid?

[assembly: Dependency( typeof( FileImplementation ) )]
namespace DartEDriver.iOS
{
   public class FileImplementation : IFile

It rejects the using statement that points to the interface (grey's it out). And while we're at it, is it grey or gray?

Thanks again.

"Catastrophic failure" error while opening xaml file

$
0
0

Few hours ago I updated to the latest Xamarin.Forms version.
Everything was fine until this update...
One of my projects is Xamarin.Forms and when I try to open .xaml file in my project I am receiving this error:

Is there any solution to this problem and why it did appear after update?

Thanks!

Issue Xamarin.Forms Could not load assembly 'Windows.Foundation.FoundationContract,

$
0
0

Hi,

I'm Building a crossplatform app for iOS, Android and UWP app using Xamarin.Forms.
I have run the Android version of the app in both an emulator and on a device which worked as would be expected.
For some reason I now run into the following exception:

Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'Windows.Foundation.FoundationContract, Version=3.0.0.0, Culture=neutral, PublicKeyToken='. Perhaps it doesn't exist in the Mono for Android profile?
File name: 'Windows.Foundation.FoundationContract.dll'
at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters) in /Users/builder/data/lanes/5749/9cfa7836/source/xamarin-android/external/Java.Interop/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/DirectoryAssemblyResolver.cs:line 229
at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(DirectoryAssemblyResolver resolver, ICollection`1 assemblies, AssemblyDefinition assembly, Boolean topLevel)
at Xamarin.Android.Tasks.ResolveAssemblies.Execute(DirectoryAssemblyResolver resolver)

I have been searching in my project but I can't find any reference to this assembly.

[0:] Binding: 'Xxx' property not found on 'Yyy', target property: 'Xamarin.Forms.Label.Text'

$
0
0

I keep getting plenty of those error warning in the output console, but every thing shows fine.
Before anyone say it, yes this property is defined on that class and it does display and update correctly.
Yet it prints this warning in the console. Zillion of times. Swamping it with spurious noise.
Anyway to remove those spurious console output?

Getting "Could not resolve type with token" error while implementing FFImageLoading in Xamarin Forms

$
0
0

Could not resolve type with token 01000081 (from typeref, class/assembly Xamarin.Forms.PlatformConfiguration.AndroidSpecific.Elevation, Xamarin.Forms.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null)

How to update Azure database connected to Xamarin.Forms app with offline sync without App crashing

$
0
0

I am developing an Xamarin.Forms App (android and IOS) which uses Azure Offline Sync. The problem I encounter is that when I have to make changes to the Database then the mobile App crashes because the local store (SQLite) is different from the Azure database.

I have searched for a solution but could not find any which works for me. Is anyone else having the same issue?

I am wondering what the best approach is when you want to make changes in the azure database and release these changes. How can you update both database and app without the user losing data or experiencing crashes?

Thanks in advance!

Xamarin.Forms iOS App Size too large

$
0
0

Hi,

I have created one application (5-6 screens) using Xamarin.Forms and everything is working good but iOS app size is very high event I didn't use any third party library. I did all possible optimizations enabled linking for all assemblies but still have app size on apple store to 40 MB (armv7s and ARM64 ). My Client ask me to reduce the app size up to 10-15 Mb.
To check the size I just created a blank iOS application, builds it with linking all assemblies and result was disappointing... total app size was 35 Mb (Apple Store Size) which is too large and no client will agree with this much of app size.

Please help me to reduce the iOS app size?


Xamarin - The type or namespace name 'App' could not be found

$
0
0

Currently getting this error trying to run my Xamarin app to my iPhone live player.

"AppDelegate.cs(1,1): error: The type or namespace name 'App' could not be found (are you missing a using directive or an assembly reference?)"
My solution builds without errors, so slightly stuck. These errors did not occur until after I updated to the most recent update. Any help is greatly appreciated.

And yes I have a reference to the PCL in the iOS project if you are wondering. Any help would be greatly appreciated.
Also everything builds correctly but when trying to deploy to an android emulator it builds correctly but the emulator is either outputing "Waiting for emulator" or remains a black screen.

App.xaml.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using COCApp;

using Xamarin.Forms;

namespace COCApp
{
    public partial class App : Application
    {
        public App()
        {
            InitializeComponent();
            MainPage = new NavigationPage(new MainPage());
        }

        protected override void OnStart()
        {
            // Handle when your app starts
        }

        protected override void OnSleep()
        {
            // Handle when your app sleeps
        }

        protected override void OnResume()
        {
            // Handle when your app resumes
        }
    }
}

AppDelegate.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using COCApp;
    using Foundation;
    using UIKit;

    namespace COCApp.iOS
    {
        // The UIApplicationDelegate for the application. This class is responsible for launching the 
        // User Interface of the application, as well as listening (and optionally responding) to 
        // application events from iOS.
        [Register("AppDelegate")]
        public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
        {
            //
            // This method is invoked when the application has loaded and is ready to run. In this 
            // method you should instantiate the window, load the UI into it and then make the window
            // visible.
            //
            // You have 17 seconds to return from this method, or iOS will terminate your application.
            //
            public override bool FinishedLaunching(UIApplication app, NSDictionary options)
            {
                global::Xamarin.Forms.Forms.Init();
                LoadApplication(new App());

                return base.FinishedLaunching(app, options);
            }
        }
    }

Xamarin.Forms for Mac Unit Tests

$
0
0

Working on a Xamarin Forms app targeting mac and I am trying to get Unit Tests working.

My project structure:
-Xamarin Mac App (Xamarin.Mac Full)
-Xamarin Mac Library (Xamarin.mac Full)
-Xamarin Shared App

These 3 work perfectly with NuGet references etc.

Creating a Nunit Library project I cannot reference the Xamarin Mac Library as it says it is incompatible with Xamarin Mac, 2.0

So then I tried creating a new Xamarin Mac app, was able to reference my Mac Library, but am getting an error at runtime: NUnit.Engine.NUnitEngineException: The NUnit 3.0 driver does not support the portable version of NUnit.

Anyone else hit this issue yet?

Mac Sleep

$
0
0

I'm aware of the flag for Android and iOS to prevent the app from going to sleep when it's not focused (i.e. UIApplication.SharedApplication.IdleTimerDisabled = true;), however what is the equivalent for Mac?

Xamarin Forms MasterDetailPage move to question

$
0
0

moved to question instead of discussion

Animate ListView viewcell Item (border or background) every 5 seconds

$
0
0

Greetings,

Does anyone know how to animate a ListView item periodically?
I am trying to animate an item every 5 seconds to catch a user attention in a Listview based on an observablecollection property.
Is the Device.StartTimer the way to tackle it and loop through all the listview items?
The animation duration should not surpass 2 seconds by increasing the border width or fading the background color of the listview item.

Can someone help or point me to the right direction please?
Any code example is much appreciated

Thank you in advance

TableView Memory Leak in iOS 11

$
0
0

Hello,

I'm experiencing what I believe is a memory leak in the latest version of Xamarin Forms when I create a TableView and add one or more EntryCells to it. I've only tested this in iOS 11 and am not currently sure if it's reproducible in older versions or in Android.

Steps to reproduce:
1. Create a new solution from the forms app template (I just followed the quickstart guide).
2. Replace the original ItemDetailPage.xaml contents with the following (removed xmlns attributes as this forum considers them links and disallows me from posting):

    <?xml version="1.0" encoding="utf-8"?>
    <ContentPage x:Class="TestApp1.ItemDetailPage" Title="{Binding Title}">
        <ScrollView Grid.Row="1">
            <StackLayout>
                <TableView Intent="Settings" VerticalOptions="Start">
                    <TableRoot>
                        <TableSection  Title="Super Secret Stuff" >
                            <EntryCell Label="MOOD" Text="Woo woo!" IsEnabled="False" HorizontalTextAlignment="End"/>
                            <EntryCell Label="REACTION" Text="Wow" IsEnabled="False" HorizontalTextAlignment="End"/>
                            <EntryCell Label="TIME" Text="Fun" IsEnabled="False" HorizontalTextAlignment="End" />
                            <EntryCell Label="FUN" Text="Much" IsEnabled="False" HorizontalTextAlignment="End"/>
                        </TableSection>
                    </TableRoot>
                </TableView>
            </StackLayout>
        </ScrollView>
    </ContentPage>
  1. Launch the app and attach XCode Instruments to it, checking for allocations.
  2. Repeatedly tap into the detail page and back out.
  3. Check Instruments and see allocations building up each time which should have been deallocated.
    __UITextTiledLayer (CALayer)
    UITableViewLabel
    ...

This doesn't seem to happen with a few of the other Xamarin Forms elements I quickly tested. I also tried changing the Xamarin Forms version to an older release, but ended up with the same results. Is there something I missed which needs to be done to properly deallocate a TableView/EntryCells? Or is this a legitimate leak in Xamarin Forms? If so, would there be any reasonable workarounds I can apply until the issue is resolved?

Thanks,
Denny Kunker

Info.plist asking for usage description keys for unneeded permissions

$
0
0

I have a very simple one page app that uses plugin.share to add a functionality of being able to copy some text to the device's clipboard. That is the only functionality that I use from that plugin and I implemented it like below.

    private async void btnCopyResults_Clicked(object sender, EventArgs e)
    {
        if (!CrossShare.Current.SupportsClipboard)
        {
            await DisplayAlert(ERROR_TITLE, "We are having some issues accessing your clipboard" +
                " to copy the results", GENERAL_ALERT_DISMIS);
            return;
        }
        else
        {
            bool isCopied = await CrossShare.Current.SetClipboardText(lblResult.Text.Trim());

            if (isCopied)
            {
                await DisplayAlert("Success", "Text copied successfully!", "Ok");
            }
        }
    }

When I send the IPA using the Application Loader everything passes but then I get an automated email like below.
I believe this plugin is the reason I am getting these but I'm not sure how to proceed or fix this as I do not need any of these permissions listed in the email below.

Furthermore, I believe all this started when I changed the Linker Behavior away from "Don't Link". It was "Don't Link" by default and I was not getting these emails but once I changed it I started getting this email for every build. I even unistalled the plugin and removed bin/ obj/ folders and installed it back and rebuild everything but nothing seems to be working.

Is there a location where I can explicitly set what permissions my app needs?

When I look in the Info.plist file those keys are not there and that is a good thing because I do not need those permissions. I'm just not sure where are they getting set at and why does my app think that it needs those.




Dear developer,
We have discovered one or more issues with your recent delivery for "---". To process your delivery, the following issues must be corrected:
Missing Info.plist key - This app attempts to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSContactsUsageDescription key with a string value explaining to the user how the app uses this data.
Missing Info.plist key - This app attempts to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSCalendarsUsageDescription key with a string value explaining to the user how the app uses this data.
Missing Info.plist key - This app attempts to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSMicrophoneUsageDescription key with a string value explaining to the user how the app uses this data.
Missing Info.plist key - This app attempts to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSAppleMusicUsageDescription key with a string value explaining to the user how the app uses this data.
Missing Info.plist key - This app attempts to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSSiriUsageDescription key with a string value explaining to the user how the app uses this data.
Though you are not required to fix the following issues, we wanted to make you aware of them:
Missing Push Notification Entitlement - Your app appears to register with the Apple Push Notification service, but the app signature's entitlements do not include the "aps-environment" entitlement. If your app uses the Apple Push Notification service, make sure your App ID is enabled for Push Notification in the Provisioning Portal, and resubmit after signing your app with a Distribution provisioning profile that includes the "aps-environment" entitlement. Xcode 8 does not automatically copy the aps-environment entitlement from provisioning profiles at build time. This behavior is intentional. To use this entitlement, either enable Push Notifications in the project editor's Capabilities pane, or manually add the entitlement to your entitlements file. For more information, see https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/HandlingRemoteNotifications.html#//apple_ref/doc/uid/TP40008194-CH6-SW1.
Once the required corrections have been made, you can then redeliver the corrected binary.
Regards,
The App Store team


GeoLocator returns null from second time

$
0
0

Hello Folks,

I have been trying get Location of the device using GeoLocator plugin. Everything works fine for the first time but it runs into NPE further. I have no idea whats happening here, Im new to Xamarin and trying to learn. I'm trying access only in iOS for now. Please help me, its been 3 days.

Here is the code.

public class FeedPage : ContentPage
{

    CLLocationManager locManager = new CLLocationManager();
    Position position;
    public FeedPage()
    {
        Title = "News Feed";
        Icon = "tab_feed.png";
        Padding = new Thickness(0, 20, 0, 0);

        var description = new Label
        {
            Text = "Learn how to use Xamarin to leverage your skills in Microsoft Visual Studio \" +\n\t\t\t\t\"and C# to build cross-platform apps that run on both Android and iOS, and embrace the features and capabilities of each platform."
        };

        var lattitude = new Label();

        var longitude = new Label();

        var stackLayout = new StackLayout();
        stackLayout.Children.Add(description);

        locManager.RequestWhenInUseAuthorization();

        var locator = CrossGeolocator.Current;
        locator.DesiredAccuracy = 50;


        async Task<double> getLocation(){
            var position =  await locator.GetLastKnownLocationAsync();
            return position.Latitude;
        }

        position.Latitude = getLocation().Result;
        stackLayout.Children.Add(lattitude);
        Content = stackLayout;


    }
}

I have added these add keys to info.plist and successfully gave access to location services.
NSLocationWhenInUseUsageDescription
This app needs to access location.
NSLocationAlwaysUsageDescription
This app needs to access location.

Thank you, happy holidays!

Santhosh

DataTemplateSelector in .net standard not working ?

$
0
0

I'm currently developping Crossplatform app that i need to show a feed of activities, each activity has its own content type and layout so i have created 5 different templates 1 for each activity type. My binding works in the sense that it calls the good template but i'm unable to show the content that i have gotten from my API...

i get a list of wich is used in my list view source
and i set its template to the datatemplate selector i have created

My page code

public ProfilePage ()
{
InitializeComponent ();
NavigationPage.SetHasNavigationBar(this, false);
ProfilePageInfos infos = API.GetProfilePageInfos();
IMG_ProfileAvatar.Source = infos.GetUserAvatarLink();
ProfilePoints.Text = infos.GetUserPoints().GetTotal() + " points";
ProfileName.Text = infos.GetUserName();

    AddGestureRecognizer(BTNHome, GetHomeGesture());
    AddGestureRecognizer(BTNPortfolio, GetPortfolioGesture());
    AddGestureRecognizer(BTNFriends, GetFriendsGesture());

    List<Feed> feed = API.GetHomeActivityFeed();
    ProfileActivities.ItemsSource = feed;
    ProfileActivities.ItemTemplate = new ActivityDataTemplateSelector();
}

My Feed class:
public class Feed
{
public Activity Activity { get; set; }
public string Name = "test name binding";
public Feed(Activity activity)
{
this.Activity = activity;
}
}

My datatemplate selector
protected override DataTemplate OnSelectTemplate(object item, BindableObject container)
{
var feed = item as Feed;
if (feed == null)
return null;
if (feed.Activity.action == "challenge_completed")
return this.activityCompletedChallenge;
else if (feed.Activity.action == "challenge_accepted")
return this.activityAcceptedChallenge;
else if (feed.Activity.action == "achievement_create")
return this.activityCustomAchievement;
else if (feed.Activity.action == "user_leveled")
{
return this.activityLevelUp;
}
else if (feed.Activity.action == "user_rank_up")
return this.activityRankUp;
else return null;
}
and My Template:
<?xml version="1.0" encoding="UTF-8"?> <ViewCell.View> <Grid.RowDefinitions> </Grid.RowDefinitions> <Grid.ColumnDefinitions> </Grid.ColumnDefinitions>

Thanks alot and happy holly days !

Xamarin Forms - Camera & Design

$
0
0

Hi there,

I'm looking from a couple of hours now about "How to design my app around my camera view"

So, I searched about how to use the camera and the Xamarin XLabs and the MediaPlugin are the ones that shows up the more.

However, when I'm looking at them, also when I'm looking at Moments, I can't find the way or understand how can we use the camera as an XAML component, to be able to design on the live view of the camera?

I'm not coding with an MVVM logic but with a MVC logic, so maybe that why I don't get it, I don't know...

Can someone help me please?

Thank in advance!

Inheritance from generic pages

$
0
0

Hello Xamarin Gurus,

I am doing a little experiment with inheritance and generics, here is the idea:
(I have a diagram to represent things more clearly, but I'm not authorised to post links yet)

The Models:

public interface IEntity { }

public abstract class Entity : IEntity
{
    public int Id { get; set; }
}

public class Instance : Entity
{
    public string Name { get; set; }
}

public class Volume : Entity
{
    public float VolumeValue { get; set; }
}

The ViewModels:

public interface IEntityViewModel<T> where T : IEntity { }

public abstract class EntityViewModel<T> : IEntityViewModel<T> where T : Entity
{
    public T Model { get; set; }
}

public class InstanceViewModel : EntityViewModel<Instance> { }

public class VolumeViewModel : EntityViewModel<Volume> { }

Now for the Views... this is where it gets complicated and broken.

EntityPage.xaml.cs:

public partial class EntityPage<T> : ContentPage where T : Entity
{
    public EntityPage(EntityViewModel<T> model)
    {
        InitializeComponent(); // error : method do not exist
        BindingContext = model;
    }
}

EntityPage.xaml:

<ContentPage x:Class="XamarinSample.View.EntityPage">
    <ContentPage.Content>
        <StackLayout >
            <Label Text="The Id is:"/>
            <Label Text="{Binding Model.Id}"/>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

VolumePage.xaml.cs:

public partial class VolumePage : EntityPage<Volume>
{
    public VolumePage(VolumeViewModel model) : base(model)
    {
        InitializeComponent();
    }
}

VolumePage.xaml:

<view:EntityPage x:TypeArguments="model:Volume" <!-- I specify the type of the generic type that EntityPage uses -->
    xmlns:view="clr-namespace:XamarinSample.View"
    xmlns:model="clr-namespace:XamarinSample.Model"
    x:Class="XamarinSample.View.VolumePage">
    <ContentPage.Content>
        <StackLayout >
            <Label Text="The VolumeValue is:"/>
            <Label Text="{Binding Model.VolumeValue}"/>
        </StackLayout>
    </ContentPage.Content>
</view:EntityPage>

The issue here is that I cannot call InitializeComponent() in the constructor of EntityPage because the generated code doesn't copy the genericity.

Generated code:

public partial class EntityPage : global::Xamarin.Forms.ContentPage {

    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Forms.Build.Tasks.XamlG", "0.0.0.0")]
    private void InitializeComponent() {
        global::Xamarin.Forms.Xaml.Extensions.LoadFromXaml(this, typeof(EntityPage));
    }
}

If I comment the problematic line and compile I get the following result from this quick&dirty initialisation:

        MainPage = new VolumePage(new ViewModel.VolumeViewModel()
        {
            Model = new Model.Volume() { Id = 50, VolumeValue = 500 }
        });

(still can't post links :neutral:)
The info about VolumeValue is displayed but not the info about the Id

Is there any way to make this work ? From the research I did prior to posting this, I would say it's not possible.

From your experience with Xamarin.Forms, would you say that it is better to use Composition over Inheritance to represent objects somewhat similar ? I am highly tempted to say yes.

Thanks in avance !

CocosSharp templates for Visual Studio 2017

Viewing all 58056 articles
Browse latest View live


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