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

Implementing Bluetooth features to Print on a bluetooth printer in Xamarin Forms App


System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocatio

$
0
0

Hi I got this error when i navigate to a page from a list view in xamarin forms . I can't find the actual problem can any one help he to find where the problem is happening from this report . am using MVVMLight
[0:] Error NavigateTo BenWorkTasksPage. Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidCastException: Specified cast is not valid. at Xamarin.Forms.Label.FontStructPropertyChanged (Xamarin.Forms.BindableObject bindable, System.Object oldValue, System.Object newValue) [0x00000] in <filename unknown>:0 at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindablePropertyContext context, System.Object value, Boolean currentlyApplying, SetValueFlags attributes, Boolean silent) [0x0010e] in <filename unknown>:0 at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes) [0x0014b] in <filename unknown>:0 at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, Boolean fromStyle, Boolean checkAccess) [0x0005f] in <filename unknown>:0 at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, Boolean fromStyle) [0x00000] in <filename unknown>:0 at Xamarin.Forms.Setter.Apply (Xamarin.Forms.BindableObject target, Boolean fromStyle) [0x000a4] in <filename unknown>:0 at Xamarin.Forms.Style.ApplyCore (Xamarin.Forms.BindableObject bindable, Xamarin.Forms.Style basedOn) [0x0001e] in <filename unknown>:0 at Xamarin.Forms.Style.Xamarin.Forms.IStyle.Apply (Xamarin.Forms.BindableObject bindable) [0x0003e] in <filename unknown>:0 at Xamarin.Forms.VisualElement+MergedStyle.SetStyle (IStyle implicitStyle, IStyle classStyle, IStyle style) [0x00111] in <filename unknown>:0 at Xamarin.Forms.VisualElement+MergedStyle.set_Style (IStyle value) [0x0000d] in <filename unknown>:0 at Xamarin.Forms.VisualElement+<>c.<.cctor>b__211_6 (Xamarin.Forms.BindableObject bindable, System.Object oldvalue, System.Object newvalue) [0x00000] in <filename unknown>:0 at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindablePropertyContext context, System.Object value, Boolean currentlyApplying, SetValueFlags attributes, Boolean silent) [0x0010e] in <filename unknown>:0 at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes) [0x0014b] in <filename unknown>:0 at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, Boolean fromStyle, Boolean checkAccess) [0x0005f] in <filename unknown>:0 at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value) [0x00000] in <filename unknown>:0 at IWSM.XamarinApp.Views.BenWorkTasksPage.InitializeComponent () [0x0af0c] in <filename unknown>:0 at IWSM.XamarinApp.Views.BenWorkTasksPage..ctor (IWSM.Shared.DataModels.WorkTaskDataModel wtdm) [0x00008] in D:\Shamnad_TFS_Workspace\IWSM.XamarinApp\IWSM.XamarinApp\IWSM.XamarinApp\Views\BenWorking\BenWorkTasksPage.xaml.cs:31 at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (System.Reflection.MonoCMethod,object,object[],System.Exception&) at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00002] in /Users/builder/data/lanes/3339/39ebb778/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:644 --- End of inner exception stack trace --- at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00016] in /Users/builder/data/lanes/3339/39ebb778/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:650 at System.Reflection.MonoCMethod.DoInvoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00089] in /Users/builder/data/lanes/3339/39ebb778/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:635 at System.Reflection.MonoCMethod.Invoke (BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in /Users/builder/data/lanes/3339/39ebb778/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:663 at System.Reflection.ConstructorInfo.Invoke (System.Object[] parameters) [0x00000] in /Users/builder/data/lanes/3339/39ebb778/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System.Reflection/ConstructorInfo.cs:62 at IWSM.XamarinApp.Common.NavigationService+<NavigateTo>d__15.MoveNext () [0x00173] in D:\Shamnad_TFS_Workspace\IWSM.XamarinApp\IWSM.XamarinApp\IWSM.XamarinApp\Common\NavigationService.cs:115 [0:] OnItemTapped: IWSM.Shared.DataModels.WorkTaskDataModel [0:] Error NavigateTo BenWorkTasksPage. Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidCastException: Specified cast is not valid. at Xamarin.Forms.Label.FontStructPropertyChanged (Xamarin.Forms.BindableObject bindable, System.Object oldValue, System.Object newValue) [0x00000] in <filename unknown>:0 at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindablePropertyContext context, System.Object value, Boolean currentlyApplying, SetValueFlags attributes, Boolean silent) [0x0010e] in <filename unknown>:0 at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes) [0x0014b] in <filename unknown>:0 at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, Boolean fromStyle, Boolean checkAccess) [0x0005f] in <filename unknown>:0 at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, Boolean fromStyle) [0x00000] in <filename unknown>:0 at Xamarin.Forms.Setter.Apply (Xamarin.Forms.BindableObject target, Boolean fromStyle) [0x000a4] in <filename unknown>:0 at Xamarin.Forms.Style.ApplyCore (Xamarin.Forms.BindableObject bindable, Xamarin.Forms.Style basedOn) [0x0001e] in <filename unknown>:0 at Xamarin.Forms.Style.Xamarin.Forms.IStyle.Apply (Xamarin.Forms.BindableObject bindable) [0x0003e] in <filename unknown>:0 at Xamarin.Forms.VisualElement+MergedStyle.SetStyle (IStyle implicitStyle, IStyle classStyle, IStyle style) [0x00111] in <filename unknown>:0 at Xamarin.Forms.VisualElement+MergedStyle.set_Style (IStyle value) [0x0000d] in <filename unknown>:0 at Xamarin.Forms.VisualElement+<>c.<.cctor>b__211_6 (Xamarin.Forms.BindableObject bindable, System.Object oldvalue, System.Object newvalue) [0x00000] in <filename unknown>:0 at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindablePropertyContext context, System.Object value, Boolean currentlyApplying, SetValueFlags attributes, Boolean silent) [0x0010e] in <filename unknown>:0 at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes) [0x0014b] in <filename unknown>:0 at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, Boolean fromStyle, Boolean checkAccess) [0x0005f] in <filename unknown>:0 at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value) [0x00000] in <filename unknown>:0 at IWSM.XamarinApp.Views.BenWorkTasksPage.InitializeComponent () [0x0af0c] in <filename unknown>:0 at IWSM.XamarinApp.Views.BenWorkTasksPage..ctor (IWSM.Shared.DataModels.WorkTaskDataModel wtdm) [0x00008] in D:\Shamnad_TFS_Workspace\IWSM.XamarinApp\IWSM.XamarinApp\IWSM.XamarinApp\Views\BenWorking\BenWorkTasksPage.xaml.cs:31 at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (System.Reflection.MonoCMethod,object,object[],System.Exception&) at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00002] in /Users/builder/data/lanes/3339/39ebb778/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:644 --- End of inner exception stack trace --- at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00016] in /Users/builder/data/lanes/3339/39ebb778/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:650 at System.Reflection.MonoCMethod.DoInvoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00089] in /Users/builder/data/lanes/3339/39ebb778/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:635 at System.Reflection.MonoCMethod.Invoke (BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in /Users/builder/data/lanes/3339/39ebb778/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:663 at System.Reflection.ConstructorInfo.Invoke (System.Object[] parameters) [0x00000] in /Users/builder/data/lanes/3339/39ebb778/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System.Reflection/ConstructorInfo.cs:62 at IWSM.XamarinApp.Common.NavigationService+<NavigateTo>d__15.MoveNext () [0x00173] in D:\Shamnad_TFS_Workspace\IWSM.XamarinApp\IWSM.XamarinApp\IWSM.XamarinApp\Common\NavigationService.cs:115

How to use a server?

$
0
0

I wrote a xamarin.forms App with iOS, UWP, Android and PCL Projects. And I have an Ubuntu Server stationed somewhere else, that I can access via ssh.

I have no experience in working with a server. So my question is, what do I still need to do, to use the Server to simply send a request and get a response for example? Or what do I need, to make a User Authetication possible?
(If its possible, I would like to use GraphQL instead of REST)

[iOS] Blank screen when navigating to another page

$
0
0

Hi,

We have a Xamarin Forms app, that compiles and runs normally on Android and iOS. Visual Studio Team Services is used for continues integration, which seems to work perfectly: we pull code into certain branches and after a while HockeyApp mails us there is a new version available. The compiling takes place on a Mac. (Mac In Cloud)

After downloading the app via HockeyApp:

  • The Android version works as it did before pushing the code to VSTS.
  • The iOS version shows a black screen after the initial (login) page.

Why would the iOS version be any different after building it with VSTS?

I've tried the xbuild and MSBuild settings and both result in a different app.
Am I missing something?

How do you setup CI for a .NET Standard Xamarin.Forms solution on VSTS?

$
0
0

Has anyone been successful in this? I've struggled to restore NuGet packages and get the UWP app to build on the server. I'm using .NET Core 2.0.0 with preview version instead of NuGet tool, but still no success.

iPhone X and safe margins with Xamarin Forms

$
0
0

Hi!

I have finished my app, but I have tested it with the iPhone X simulator and I'm totally out of the safe margins.

I'm searching for info everywhere, but I can't find anything specific to that.

I have alleviated the problem using always a NavigationBar, but the problem still persists if I put the device in landscape mode.

Does someone know how to apply extra margins if necessary with the iPhone X?

Thanks!

Detect specific device

$
0
0

Is there any way to detect a specific device (type)? More exactly I want to know if a user uses a iPhone X (or a iOS device with no physical Home Button). That's because I have to apply some specific margins/paddings for these devices and it just look ugly on other devices. Because the "virtual home bar" at the bottom is overlaying some content (yes, I know that this device is not released yet, but I have to fix it for a few Apps so I start early). And of corse for the site if the device is in landscape. Therefore I also need to differ between Top -> Left and Top -> Right Landscape modes. Also I need to differ in C# as well in XAML.

Issue with VS2017/Forms 2.5.0.121934

$
0
0

I had been working without issue until the latest update for VS 2017 came out, 15.5.2. I chose to perform the update and since have been receiving the following error:

Severity Code Description Project File Line Suppression State
Error The "ResolveLibraryProjectImports" task failed unexpectedly.
System.IO.FileNotFoundException: Could not load assembly 'Windows.Foundation.UniversalApiContract.winmd, Version=0.0.0.0, Culture=neutral, PublicKeyToken='. Perhaps it doesn't exist in the Mono for Android profile?
File name: 'Windows.Foundation.UniversalApiContract.winmd.dll'
at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters) in /Users/builder/data/lanes/5147/c2a33d8e/source/xamarin-android/external/Java.Interop/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/DirectoryAssemblyResolver.cs:line 220
at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(String fullName) in /Users/builder/data/lanes/5147/c2a33d8e/source/xamarin-android/external/Java.Interop/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/DirectoryAssemblyResolver.cs:line 160
at Xamarin.Android.Tasks.ResolveLibraryProjectImports.Extract(DirectoryAssemblyResolver res, ICollection1 jars, ICollection1 resolvedResourceDirectories, ICollection1 resolvedAssetDirectories, ICollection1 resolvedEnvironments)
at Xamarin.Android.Tasks.ResolveLibraryProjectImports.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext() CoDev.PowerFleetApp.Android

Thinking it may have been an issue with the update, I rolled it back to version 15.4.5, ensuring I did a clean install. No luck.

Anyone else having this issue? Any thoughts as to what I need to do to move on?

p.s. I also attempted a few Nuget updated however latest versions of some of the Android packages will not install because of the version of forms I am on now. Example:
Severity Code Description Project File Line Suppression State
Error Unable to resolve dependencies. 'Xamarin.Android.Support.v4 26.1.0.1' is not compatible with 'Xamarin.Forms 2.5.0.121934 constraint: Xamarin.Android.Support.v4 (= 23.3.0)'. 0


Shared library

$
0
0
Hello all

I am developing an app that will have a asp.net core 2.0 website as well as Xamarin Forms Android and iOS apps. I need to have a library or dll that can be shared across the Xamarin Forms and asp.net core 2.0 app. I am not going for cross platform with asp.net core, it will be a windows deployment. Can I use a simple .net class library or do I need something else?

Thanks in advance!

Why my app crash after scrolling ListView with SubItems

$
0
0

XAML CODE:



<ListView.Header>

<Grid.ColumnDefinitions>


</Grid.ColumnDefinitions>
<Grid.RowDefinitions>



</Grid.RowDefinitions>

                <Image Source="icon.png"
                       Grid.Column="0" VerticalOptions="FillAndExpand"
                       Grid.Row="1"/>
                <Label Grid.Column="1" Grid.Row="1" TextColor="White"
                       x:Name="lblUser" FontSize="26" FontAttributes="Bold"
                       Text="Usurio" VerticalOptions="Start"/>
                <Label Grid.Column="1" Grid.Row="1" TextColor="White"
                       FontSize="16" Text="correoelectronico@correo.com"
                       VerticalOptions="End"/>
            </Grid>
        </ListView.Header>
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <StackLayout Padding="15,10" HorizontalOptions="FillAndExpand">
                        <ListView x:Name="ItemsListView"
                                  SeparatorVisibility="None"
                                  HasUnevenRows="true"
                                  ItemsSource="{Binding Items}">
                            <ListView.Header>
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="40"/>
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="40"/>
                                    </Grid.ColumnDefinitions>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="40"/>
                                    </Grid.RowDefinitions>
                                    <Image Source="{Binding ImageHeader}"
                                           Grid.Column="0" Grid.Row="0"/>
                                    <Label VerticalOptions="FillAndExpand"
                                           VerticalTextAlignment="Center"
                                           Text="{Binding TitleHeader}"
                                           FontSize="24"
                                           Grid.Column="1" Grid.Row="0"/>
                                    <Image Source="ic_arrow_down.png"
                                           Grid.Column="2" Grid.Row="0"/>
                                </Grid>
                            </ListView.Header>
                            <ListView.ItemTemplate>
                                <DataTemplate>
                                    <ViewCell>
                                        <StackLayout Margin="20,0,0,0">
                                            <Grid>
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="40"/>
                                                    <ColumnDefinition Width="*"/>
                                                    <ColumnDefinition Width="40"/>
                                                </Grid.ColumnDefinitions>
                                                <Grid.RowDefinitions>
                                                    <RowDefinition Height="40"/>
                                                </Grid.RowDefinitions>
                                                <Image Source="{Binding Image}"
                                                       Grid.Column="0" Grid.Row="0"/>
                                                <Label VerticalOptions="FillAndExpand"
                                                       VerticalTextAlignment="Center"
                                                       Text="{Binding Title}"
                                                       FontSize="18"
                                                       Grid.Column="1" Grid.Row="0"/>
                                                <Image Source="ic_arrow_down.png"
                                                       Grid.Column="2" Grid.Row="0"/>
                                            </Grid>
                                        </StackLayout>
                                    </ViewCell>
                                </DataTemplate>
                            </ListView.ItemTemplate>
                        </ListView>
                    </StackLayout>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
</StackLayout>

CS CODE:

[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class HomeMaster : ContentPage
{
public ListView ListView;

    public HomeMaster()
    {
        InitializeComponent();

        BindingContext = new HomeMasterViewModel();
        ListView = MenuItemsListView;
    }

    class HomeMasterViewModel : INotifyPropertyChanged
    {
        public ObservableCollection<HomeMenuItem> MenuItems { get; set; }

        public HomeMasterViewModel()
        {
            MenuItems = new ObservableCollection<HomeMenuItem>(new[]
            {
                new HomeMenuItem ("Page 1", "ic_monetization.png",new ObservableCollection<Item> {
                    new Item("Item 1", "ic_help.png", null), new Item("Item 2", "ic_help.png", null)} ),
                new HomeMenuItem ("Page 2", "ic_monetization.png",new ObservableCollection<Item> {
                    new Item("Item 1", "ic_help.png", null), new Item("Item 2", "ic_help.png", null)} ),
                new HomeMenuItem ("Page 3", "ic_monetization.png",new ObservableCollection<Item> {
                    new Item("Item 1", "ic_help.png", null), new Item("Item 2", "ic_help.png", null)} ),

            });
        }

        #region INotifyPropertyChanged Implementation
        public event PropertyChangedEventHandler PropertyChanged;
        void OnPropertyChanged([CallerMemberName] string propertyName = "")
        {
            if (PropertyChanged == null)
                return;

            PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
        #endregion
    }
}

Error Executing task LinkAssemblies for Android Release Build

$
0
0

I recently built an application using Xamarin.Forms. The Android app runs fine when using the Debug profile for compilation, however when switching over to Release then compiling it, I get:

/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets:

Error: Error executing task LinkAssemblies: error XA2006: Reference to metadata
item 'Android.Text.InputTypes Android.Widget.SearchView::get_InputType()'
(defined in 'Xamarin.Forms.Platform.Android, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null') from 'Xamarin.Forms.Platform.Android, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null' could not be resolved.
(USFSPConnect.Android)

I'm running the latest version of Xamarin, Xamarin.Android & have the latest version of Xamarin.Forms from Nuget. This happens on Mac OS X 10.10 and Windows 7/8. Has anyone had a similar issue?

How to do data-binding between an sqlite database and a listview?

$
0
0

I'm trying to use data-binding to get list of contacts from an sqlite database. So far I've followed the guide on working with databases but my listview isn't displaying any numbers.

How to do data-binding between a sqlite database and a listview?

$
0
0

I have tried using the guide on using local databases and reading the working application (Tasky) source code to get an idea of how i could achieve this but my listview remains empty. This is my code:

This is my model:
public class AppUser
{
[PrimaryKey, AutoIncrement]
public long AppUserId { get; set; }

        [MaxLength(255)]
        public string Name { get; set; }
        [MaxLength(255)]
        public string ContactName { get; set; }
        public string Password { get; set; }
        public string MedicalNumber { get; set; }
        public string PoliceNumber { get; set; }
        public string FireNumber { get; set; }
        public string FamilyNumber { get; set; }
        public string CustomTextMessage { get; set; }



    }

This is my data access layer
public class AppUserDbConnect
{
static SQLiteAsyncConnection _database;

    public AppUserDbConnect(string dbPath)
    {
        _database = new SQLiteAsyncConnection(dbPath);
        _database.CreateTableAsync<AppUser>().Wait();
    }
    public Task<List<AppUser>> GetItemsAsync()
    {
        return _database.Table<AppUser>().ToListAsync();
    }

    public Task<List<AppUser>> GetItemsNotDoneAsync()
    {
        return _database.QueryAsync<AppUser>("SELECT * FROM [AppUser] WHERE [Done] = 0");
    }

    public Task<AppUser> GetItemAsync(int id)
    {
        return _database.Table<AppUser>().Where(i => i.AppUserId == id).FirstOrDefaultAsync();
    }

    public Task<int> SaveItemAsync(AppUser item)
    {
        if (item.AppUserId != 0)
        {
            return _database.UpdateAsync(item);
        }
        else
        {
            return _database.InsertAsync(item);
        }
    }

    public Task<int> DeleteItemAsync(AppUser item)
    {
        return _database.DeleteAsync(item);
    }
}

}

This is my view:

        <StackLayout>
            <Label Text="SETTINGS/MY Numbers" FontSize="30" FontAttributes="Bold"/>
        <ListView x:Name="ListOfNumbers" >

            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <ViewCell.View>
                            <Label Text="{Binding MedicalNumber}" />
                        </ViewCell.View>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>

        </ListView>
    </StackLayout>

</ContentPage>

And finally the code behind:
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MyNumbersPage : ContentPage
{

                    public MyNumbersPage ()

                    {

                        InitializeComponent( );
                         BindingContext = new AppUser();

                    }
                    protected async override void OnAppearing()
                    {
                        base.OnAppearing();
                        ListOfNumbers.ItemsSource = await App.AppUserDatabase.GetItemsAsync();

                    }

                }

'System.Exception' in Xamarin.Forms.Xaml.dll

$
0
0

Whenever I try to run my App in Android or UWP, I get the following error message:

Exception thrown: 'System.Exception' in Xamarin.Forms.Xaml.dll
An exception of type 'System.Exception' occurred in Xamarin.Forms.Xaml.dll but was not handled in user code
Expression must end with '}'

This seems to occur, in the XAML.cs file. LoadApplication(new FootballStatsApp.App());.

Any suggestions on how to fix this?

Xamarin.Forms LocationManager error on RequestLocationUpdates

$
0
0

Hello everyone.
I am developing an app with Xamarin.Forms that allows me to know the time by taking it from the GPS.
To do this I'm taking advantage of the LocationManager class in the MainActivity but unfortunately just launch the RequestLocationUpdates method the app crashes.
The detail of the crash is as follows

12-18 16:30:50.837 D/Mono (25728): Assembly Ref addref Xamarin.Android.Support.Fragment[0xadccd700] -> Xamarin.Android.Support.Media.Compat[0xadccd7c0]: 2
12-18 16:30:51.087 D/Mono (25728): Assembly Ref addref Xamarin.Android.Support.Fragment[0xadccd700] -> Xamarin.Android.Support.Core.Utils[0xadccd580]: 3
12-18 16:31:20.927 E/art (25728): JNI ERROR (app bug): attempt to pass an instance of md52f4761d89c43914387d849b16f8eb064.MainActivity as argument 4 to void android.location.LocationManager.requestLocationUpdates(java.lang.String, long, float, android.location.LocationListener)
referenceTable GDEF length=814 1
referenceTable GSUB length=11364 1
referenceTable GPOS length=47302 1
12-18 16:31:20.977 F/art 12-18 16:31:20.977 F/art (25728): art/runtime/java_vm_ext.cc:410] JNI DETECTED ERROR IN APPLICATION: bad arguments passed to void android.location.LocationManager.requestLocationUpdates(java.lang.String, long, float, android.location.LocationListener) (see above for details)
12-18 16:31:20.977 F/art (25728): art/runtime/java_vm_ext.cc:410] from void md52f4761d89c43914387d849b16f8eb064.MainActivity.n_onCreate(android.os.Bundle)
12-18 16:31:20.977 F/art (25728): art/runtime/java_vm_ext.cc:410] "main" prio=5 tid=1 Runnable
12-18 16:31:20.977 F/art (25728): art/runtime/java_vm_ext.cc:410] | group="main" sCount=0 dsCount=0 obj=0x76537598 self=0xb4864500
12-18 16:31:20.977 F/art (25728): art/runtime/java_vm_ext.cc:410] | sysTid=25728 nice=-11 cgrp=apps sched=0/0 handle=0xb6fe5b4c
12-18 16:31:20.977 F/art (25728): art/runtime/java_vm_ext.cc:410] | state=R schedstat=( 3438601580 197147438 1598 ) utm=265 stm=78 core=0 HZ=100
12-18 16:31:20.977 F/art (25728): art/runtime/java_vm_ext.cc:410] | stack=0xbe3f3000-0xbe3f5000 stackSize=8MB
12-18 16:31:20.977 F/art (25728): art/runtime/java_vm_ext.cc:410] | held mutexes= "mutator lock"(shared held)
12-18 16:31:20.977 F/art (25728): art/runtime/java_vm_ext.cc:410] native: #00 pc 00371871 /system/lib/libart.so (ZN3art15DumpNativeStackERNSt3__113basic_ostreamIcNS0_11char_traitsIcEEEEiPKcPNS_9ArtMethodEPv+160)
12-18 16:31:20.977 F/art (25728): art/runtime/java_vm_ext.cc:410] native: #01 pc 00350eeb /system/lib/libart.so (_ZNK3art6Thread4DumpERNSt3__113basic_ostreamIcNS1_11char_traitsIcEEEE+150)
12-18 16:31:20.977 F/art (25728): art/runtime/java_vm_ext.cc:410] native: #02 pc 0025aed5 /system/lib/libart.so (_ZN3art9JavaVMExt8JniAbortEPKcS2
+740)
12-18 16:31:20.977 F/art (25728): art/runtime/java_vm_ext.cc:410] native: #03 pc 0025b62b /system/lib/libart.so (_ZN3art9JavaVMExt9JniAbortFEPKcS2_z+74)
12-18 16:31:20.977 F/art (25728): art/runtime/java_vm_ext.cc:410] native: #04 pc 0032c5ab /system/lib/libart.so (_ZN3artL20CheckMethodArgumentsEPNS_9JavaVMExtEPNS_9ArtMethodEPj+1566)
12-18 16:31:20.977 F/art (25728): art/runtime/java_vm_ext.cc:410] native: #05 pc 0032d619 /system/lib/libart.so (_ZN3art35InvokeVirtualOrInterfaceWithJValuesERKNS_33ScopedObjectAccessAlreadyRunnableEP8_jobjectP10_jmethodIDP6jvalue+716)
12-18 16:31:20.977 F/art (25728): art/runtime/java_vm_ext.cc:410] native: #06 pc 00295701 /system/lib/libart.so (_ZN3art3JNI15CallVoidMethodAEP7_JNIEnvP8_jobjectP10_jmethodIDP6jvalue+344)
12-18 16:31:20.977 F/art (25728): art/runtime/java_vm_ext.cc:410] native: #07 pc 0010fadd /system/lib/libart.so (_ZN3art8CheckJNI11CallMethodAEPKcP7_JNIEnvP8_jobjectP7_jclassP10_jmethodIDP6jvalueNS_9Primitive4TypeENS_10InvokeTypeE+928)
12-18 16:31:20.977 F/art (25728): art/runtime/java_vm_ext.cc:410] native: #08 pc 00110569 /system/lib/libart.so (_ZN3art8CheckJNI15CallVoidMethodAEP7_JNIEnvP8_jobjectP10_jmethodIDP6jvalue+36)
12-18 16:31:20.977 F/art (25728): art/runtime/java_vm_ext.cc:410] native: #09 pc 00008b4f /data/app/com.companyname.BluetoothTest-1/lib/arm/libmonodroid.so (java_interop_jnienv_call_void_method_a+28)
12-18 16:31:20.977 F/art (25728): art/runtime/java_vm_ext.cc:410] native: #10 pc 0002bef8 (???)
12-18 16:31:20.977 F/art (25728): art/runtime/java_vm_ext.cc:410] at md52f4761d89c43914387d849b16f8eb064.MainActivity.n_onCreate(Native method)
12-18 16:31:20.977 F/art (25728): art/runtime/java_vm_ext.cc:410] at md52f4761d89c43914387d849b16f8eb064.MainActivity.onCreate(MainActivity.java:30)
12-18 16:31:20.977 F/art (25728): art/runtime/java_vm_ext.cc:410] at android.app.Activity.performCreate(Activity.java:6876)
12-18 16:31:20.977 F/art (25728): art/runtime/java_vm_ext.cc:410] at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
12-18 16:31:20.977 F/art (25728): art/runtime/java_vm_ext.cc:410] at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206)
12-18 16:31:20.977 F/art (25728): art/runtime/java_vm_ext.cc:410] at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
12-18 16:31:20.977 F/art (25728): art/runtime/java_vm_ext.cc:410] at android.app.ActivityThread.access$1100(ActivityThread.java:221)
12-18 16:31:20.977 F/art (25728): art/runtime/java_vm_ext.cc:410] at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
12-18 16:31:20.977 F/art (25728): art/runtime/java_vm_ext.cc:410] at android.os.Handler.dispatchMessage(Handler.java:102)
12-18 16:31:20.977 F/art (25728): art/runtime/java_vm_ext.cc:410] at android.os.Looper.loop(Looper.java:158)
12-18 16:31:20.977 F/art (25728): art/runtime/java_vm_ext.cc:410] at android.app.ActivityThread.main(ActivityThread.java:7225)
12-18 16:31:20.977 F/art (25728): art/runtime/java_vm_ext.cc:410] at java.lang.reflect.Method.invoke!(Native method)
12-18 16:31:20.977 F/art (25728): art/runtime/java_vm_ext.cc:410] at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
12-18 16:31:20.977 F/art (25728): art/runtime/java_vm_ext.cc:410] at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
12-18 16:31:20.977 F/art (25728): art/runtime/java_vm_ext.cc:410]
12-18 16:31:20.977 F/art (25728): art/runtime/runtime.cc:368] Runtime aborting...
12-18 16:31:20.977 F/art (25728): art/runtime/runtime.cc:368]
12-18 16:31:20.977 F/libc (25728): Fatal signal 6 (SIGABRT), code -6 in tid 25728 (e.BluetoothTest)

This is the code I use:

`using System;
using Android.App;
using Android.Content.PM;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Android.Bluetooth;
using Android.Content;
using Android.Locations;
using System.Collections.Generic;
using System.Linq;
using BluetoothTest.Droid;

[assembly: Xamarin.Forms.Dependency(typeof(MainActivity))]
namespace BluetoothTest.Droid
{

[Activity(Label = "BluetoothTest", Icon = "@drawable/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity, IOra, ILocationListener
{
    LocationManager _locationManager;
    Location _currentLocation;
    string _locationProvider;

    public DateTime OraGPS;

    protected override void OnCreate(Bundle bundle)
    {
        TabLayoutResource = Resource.Layout.Tabbar;
        ToolbarResource = Resource.Layout.Toolbar;

        base.OnCreate(bundle);

        global::Xamarin.Forms.Forms.Init(this, bundle);
        LoadApplication(new App());

        Bth.Receiver ricevitore = new Bth.Receiver(this);
        var filter = new IntentFilter(BluetoothDevice.ActionFound);
        RegisterReceiver(ricevitore, filter);

        InitializeLocationManager();

    }

    protected override void OnResume()
    {
        base.OnResume();

        _locationManager.RequestLocationUpdates(_locationProvider, 0, 0, this);
    }

    public void OnLocationChanged(Location location)
    {
        _currentLocation = location;
        if (_currentLocation != null)
        {
            OraGPS = new DateTime(location.Time, DateTimeKind.Utc);
        }
    }

    public string GetOra()
    {
        string ora = OraGPS.ToString();

        return ora;
    }

    void InitializeLocationManager()
    {
        _locationManager = (LocationManager)GetSystemService(LocationService);


            Criteria criteriaForLocationService = new Criteria
            {
                Accuracy = Accuracy.Fine
            };

            IList<string> acceptableLocationProviders = _locationManager.GetProviders(criteriaForLocationService, true);

            if (acceptableLocationProviders.Any())
            {

            _locationProvider = acceptableLocationProviders.First();



            _locationManager.RequestLocationUpdates("gps", 5000, 10, this);

            }
            else
            {
                _locationProvider = string.Empty;
            }


    }

    public void OnProviderDisabled(string provider) { }

    public void OnProviderEnabled(string provider) { }

    public void OnStatusChanged(string provider, Availability status, Bundle extras) { }
}

}`

but at line
_locationManager.RequestLocationUpdates("gps", 5000, 10, this);

App crashes....
Where is problem???
I think the problem refers to the parameters passed to the method and in particular to the parameter "this" because it does not see it with LocationListener.

how could I solve?
Could you give me some indication?
My need is to get the date and time from the GPS regardless of the one set on the device when there is no internet connection.

I thank you so much for your help.


Xamarin.Forms Speech to Text crashes on iPad iOS

$
0
0

Hi,

I have an app developed in Xamarin.Forms. I Used SpeechToText functionality in the app. It works fine on Android and iPhone, but on iPad it failed with following run time exception on first or second tap:

Hardware Model: iPad4,8
OS Version: iPhone OS 10.2.1 (14D27)

```
Application Specific Information:
*** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: IsFormatSampleRateAndChannelCountValid(format)'

    Last Exception Backtrace:
    0   CoreFoundation                       0x000000018cddd1b8 __exceptionPreprocess + 124
    1   libobjc.A.dylib                      0x000000018b81455c objc_exception_throw + 52
    2   CoreFoundation                       0x000000018cddd08c +[NSException raise:format:arguments:] + 100
    3   AVFAudio                             0x00000001a62a3300 AVAE_RaiseException(NSString*, ...) + 56
    4   AVFAudio                             0x00000001a6318abc AVAudioNodeImplBase::CreateRecordingTap(unsigned long, unsigned int, AVAudioFormat*, void (AVAudioPCMBuffer*, AVAudioTime*) block_pointer) + 268
    5   AVFAudio                             0x00000001a6316718 -[AVAudioNode installTapOnBus:bufferSize:format:block:] + 212
    6   AgriSynciOS                          0x00000001015d7588 wrapper_managed_to_native_ObjCRuntime_Messaging_objc_msgSend_intptr_intptr_System_nuint_uint_intptr_intptr (<unknown>:1)
    7   AgriSynciOS                          0x0000000101590788 AVFoundation_AVAudioNode_InstallTapOnBus_System_nuint_uint_AVFoundation_AVAudioFormat_AVFoundation_AVAudioNodeTapBlock (AVAudioNode.g.cs:118)

````
Below is the code (used with Dependencyservice):
` public class SpeechToTextImplementation : ISpeechToText
{
private Action _callback;

    #region Private Variables
    private AVAudioEngine AudioEngine;
    private SFSpeechRecognizer SpeechRecognizer;
    private SFSpeechAudioBufferRecognitionRequest LiveSpeechRequest;
    private SFSpeechRecognitionTask RecognitionTask;
    #endregion

    public SpeechToTextImplementation()
    {

    }

    public void InitializeProperties()
    {
        try
        {
            if (AudioEngine == null)
                AudioEngine = new AVAudioEngine();
            if (SpeechRecognizer == null)
                SpeechRecognizer = new SFSpeechRecognizer();
            if (LiveSpeechRequest == null)
                LiveSpeechRequest = new SFSpeechAudioBufferRecognitionRequest();
        }
        catch (Exception ex)
        {
            LogController.LogError(ex.Message, ex);
        }
    }

    public void Start(Action<EventArgsVoiceRecognition> handler)
    {
        _callback = handler;
        AskPermission();
    }

    public void Stop()
    {
        CancelRecording();
    }

    void AskPermission()
    {
        try
        {
            // Request user authorization
            SFSpeechRecognizer.RequestAuthorization((SFSpeechRecognizerAuthorizationStatus status) =>
            {
                // Take action based on status
                switch (status)
                {
                    case SFSpeechRecognizerAuthorizationStatus.Authorized:
                        InitializeProperties();
                        StartRecordingSession();
                        break;
                    case SFSpeechRecognizerAuthorizationStatus.Denied:
                        // User has declined speech recognition

                        break;
                    case SFSpeechRecognizerAuthorizationStatus.NotDetermined:
                        // Waiting on approval

                        break;
                    case SFSpeechRecognizerAuthorizationStatus.Restricted:
                        // The device is not permitted

                        break;
                }
            });
        }
        catch (Exception ex)
        {
            LogController.LogError("SpeechRecognition::AskPermission", ex);
        }
    }

    public void StartRecordingSession()
    {
        try
        {
    //var format = new AVAudioFormat(AVAudioCommonFormat.PCMInt16, 44100, 2, false);

            // Start recording
            AudioEngine.InputNode.InstallTapOnBus(
                bus: 0,
                bufferSize: 1024,
                format: AudioEngine.InputNode.GetBusOutputFormat(0),
                tapBlock: (buffer, when) => LiveSpeechRequest?.Append(buffer)); ///Throw exception from here.

            AudioEngine.Prepare();
            NSError error;
            AudioEngine.StartAndReturnError(out error);
            //AudioEngine.MainMixerNode.
            // Did recording start?
            if (error != null)
            {
                return;
            }

            CheckAndStartReconition();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }

    public void CheckAndStartReconition()
    {
        if (RecognitionTask?.State == SFSpeechRecognitionTaskState.Running)
        {
            CancelRecording();
        }
        StartVoiceRecognition();
    }

    public void StartVoiceRecognition()
    {
        try
        {
            RecognitionTask = SpeechRecognizer.
                GetRecognitionTask(LiveSpeechRequest,
                (SFSpeechRecognitionResult result, NSError err) =>
            {
                try
                {
                    if (result == null)
                    {
                        CancelRecording();
                        return;
                    }
                    // Was there an error?
                    if (err != null)
                    {
                        CancelRecording();
                        return;
                    }
                    //   Is this the final translation?
                    if (result != null && result.BestTranscription != null && result.BestTranscription.FormattedString != null)
                    {
                        Console.WriteLine("You said \"{0}\".", result.BestTranscription.FormattedString);
                        TextChanged(result.BestTranscription.FormattedString);
                    }
                    if (result.Final)
                    {
                        TextChanged(result.BestTranscription.FormattedString, true);
                        CancelRecording();
                        return;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    CancelRecording();
                }
            });
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }

    public void StopRecording()
    {
        try
        {
            AudioEngine?.Stop();
            LiveSpeechRequest?.EndAudio();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }

    public void CancelRecording()
    {
        try
        {
            AudioEngine?.Stop();
            RecognitionTask?.Cancel();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }

    public void TextChanged(string text, bool isFinal = false)
    {
        // textChanged?.Invoke(this, new EventArgsVoiceRecognition(text, isFinal));
        if (_callback != null)
            _callback(new EventArgsVoiceRecognition(text, true));
    }
}

`

Any thought on this?

How to diagnose - Java.Lang.RuntimeException: Unable to instantiate activity ComponentInfo

$
0
0

I am using VS2017 with the latest Xamarin updates 15.5.2. I have an application that I was recompiling with one change in some logic. When I attempt to debug the application on a android attached tablet, I get the following error message:

Unhandled Exception:

Java.Lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.sacssoftware.sacsmaint/md58f2d4d6a295913cb92633ff5b036c6a8.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "md58f2d4d6a295913cb92633ff5b036c6a8.MainActivity" on path: DexPathList[[zip file "/data/app/com.sacssoftware.sacsmaint-1/base.apk"],nativeLibraryDirectories=[/data/app/com.sacssoftware.sacsmaint-1/lib/arm, /system/fake-libs, /data/app/com.sacssoftware.sacsmaint-1/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]

What steps can I take to troubleshoot this problem?

The application previously worked when compiled with the older Xamarin VS releases. I went back to an archived copy of the application when it worked and it still compiles and debugs with the above error. It crashes on the tablet when I attempt to start it outside of the debugger.

Dan

Trouble while creating a XAML file and not able to compile project due to that XAML file

$
0
0

Hi,

I'm new to Xamarin.

I want to build a simple page that has a button can navigate to another page.

But when i was creating a "Content Page using XAML" (Right click --> Add new items...) for the navigation page.

There was a WARNING message box show up: Exception of type "System.Exception"

And then another warning message show up said something like page1 should be page type, page1 should belong to the project, ... something like that. I don't remember well. Sorry i didn't capture that screen. But i am able to add a Content Page normally.

After i added the Content Page, when starting debugging, there was an error message in the error list told me that "InitializeComponent" does not exist.

If i deleted that Content Page, everything would work normally.

I started to screwing around a bit and found out that if i just add a Content Page using C#, it works well. I know that i can design a content page by coding in c# but since i'm new to this i think maybe write the content in XAML would be better for me.

My question is why my Visual Studio can't compile the "InitializeComponent" in a Content Page using XAML i add, but it can compile "InitializeComponent" in the default MainPage using XAML? And how can i solve this?

Here is the log file i got.!

Simplest way to draw a single pixel on Xamarin Forms ContentPage?

$
0
0

Hi,
maybe with SkiaSharp (in Xamarin Forms) @mattleibow?
Or can i detect touch event and draw a BoxView 1x1? (but i hope drawing 500 boxview will decrease app performance?).
I use SignaturePad, but i have to do it in UWP, and this component doesn't support it.

Thank you for any suggest!

Lewix

How to set `RowHeight` for ListView as Platform Specific .

$
0
0

is it possible to set RowHeight of ListView as Platform Specific ?
i did with this-

<ListView.RowHeight> <OnPlatform x:TypeArguments="x:Double"> <On Platform="iOS" Value="65" /> <On Platform="Android" Value="70" /> </OnPlatform> </ListView.RowHeight>

but i getting below error -

Position 255:22. No property, bindable property, or event found for 'RowHeight

Viewing all 89864 articles
Browse latest View live


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