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

How to clear all chirldren on Xamarin.Forms.Maps Control?

$
0
0

Hi everybody!
I have use CustomRenderer to draw some circle, now i need a button to clear all that circle.
i can clear on Android, but on UWP the map DO NOT clear children
Control.Children.Clear();
nativeMap = Control;


Hello! When clicking an text-entry-box i get null reference exception object reference not set to an

$
0
0

"Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object."

This is my xaml code from the page in which the text-entry-box is in. The exception is thrown when I click on the entry box, before I am able to type anything in it.
----xaml, the page with the entry box--------

<ContentPage.BindingContext>

</ContentPage.BindingContext>

<ContentPage.Content>
    <StackLayout HorizontalOptions="Center" VerticalOptions="Center" Spacing="10">

        <Entry Text="{Binding Keyword}"  MaxLength="15"/>

        <Button Text="Send" BorderColor="Black" TextColor="White"   FontAttributes="Bold" FontSize="20" BackgroundColor="#f49131" 
    Command="{Binding CheckCommand}" x:Name="send" IsVisible="true" CornerRadius="10"/>

</StackLayout>

</ContentPage.Content>

And this is the code from the viewmodel, which is the bindingcontext to the former page ^^

public string Keyword { get; set; }  <----- this is what the entry box's text is binded to.
    public int ID { get; set; }

    public ICommand CheckCommand
    {
        get
        {
            return new Command(async () =>
            {


                Checks = await _apiServices.GetCheckAsync(Keyword);
                if (_checks.Count > 0)
                {                         
                        Settings.Chk = "true";                          

                        await Application.Current.MainPage.DisplayAlert("message", "message.", "ok");                        
                 } 
                    else
                    {
                        await Application.Current.MainPage.DisplayAlert("Feil kode", "Det oppstod en feil.", "ok");
                    }
                }        
            });
        }

}

Copy File to Downloads

$
0
0

Hi Guys I want to copy my sqlite database to the sd card or else downloads folder is thier a way to do this and also where is the best place to keep the db anyway i was thinking the sd card and if so how can i store it on sd card in the emulator is their an easy way to do this at all?. Using Xamarin forms.

public async Task copydb()
{
DatabasePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "StockApp9.db");

    if (!File.Exists(DatabasePath))

    {

        using (var assetStream = await Xamarin.Essentials.FileSystem.OpenAppPackageFileAsync("StockApp9.db"))
        using (var fileStream = new FileStream(DatabasePath, FileMode.Create, FileAccess.Write))
        {
            assetStream.CopyTo(fileStream);
        }
    }
    database = new SQLiteAsyncConnection(DatabasePath);

}

This works but no matter where on the emulator i look I cannot find the file. I can access the file ok and no it exists on the device ok. As can see the data i put into it their.

In a single app, it seems only allow one picker

$
0
0

I have a picker in a content page, after I add another picker in another content page the second picker always gets error of Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference occurred. Any suggestion?

Help about conference app of Xamarin Evolve

$
0
0
Hello guys. I need some help with finding a xamarin account because i am trying to study this https://github.com/xamarinhq/app-conference
It is the conference app from xamarin evolve, but i cant login and when i try to signup it sends you to a 404 microsoft page. So if anyone has a xamarin account that i can use to login or has an idea how to login then please let me know.

Thanks in advance.

SignaturePad - Disable finger input - Stylus only

$
0
0

Is it possible to disable finger input for SignaturePad? I have the control within a scrollview and everytime we scroll, we get a vertical line through the signature area.

Hoping there was a way I could disable finger input and allow navigation as normal unless a stylus is trying to input data (kinda like iPad / Apple Pencil / Notability)

Why i am getting Newtonsoft.Json.JsonSerializationException in xamarin android while release time?

$
0
0

android.runtime.JavaProxyThrowable: Newtonsoft.Json.JsonSerializationException: Unable to find a constructor to use for type Model class.

A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute. Path 'status', line 1, position 10.
[AndroidRuntime] at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateNewObject (Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonObjectContract objectContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, Newtonsoft.Json.Serialization.JsonProperty containerProperty, System.String id, System.Boolean& createdFromNonDefaultCreator) [0x000d5] in <7ead8a5d25b446818eaba4cd3ba7f8d1>:0
[AndroidRuntime] at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) [0x00148] in <7ead8a5d25b446818eaba4cd3ba7f8d1>:0
[AndroidRuntime] at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) [0x0006d] in <7ead8a5d25b446818eaba4cd3ba7f8d1>:0
[AndroidRuntime] at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType, System.Boolean checkAdditionalContent) [0x000db] in <7ead8a5d25b446818eaba4cd3ba7f8d1>:0
[AndroidRuntime] at Newtonsoft.Json.JsonSerializer.DeserializeInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00054] in <7ead8a5d25b446818eaba4cd3ba7f8d1>:0
[AndroidRuntime] at Newtonsoft.Json.JsonSerializer.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00000] in <7ead8a5d25b446818eaba4cd3ba7f8d1>:0

Can you please suggest me for this issue? While debug time its working fine but, when its getting release APK only?

Xamarin Forms - Shell Flyout without items?

$
0
0

Hi, I want to use "shell", but I'm trying to make the shell flyout content without items, I want to build my own content on that section, it there a way for do it?

I don't want to use the 1 picture + title.

I mean the middle part on this picture:


Visual Studio 2019 Android Emulator Not Started

$
0
0

Hi Everyone, I installed VS 2019 Community but android emulator not workıng
output;
Starting emulator 2019emulator ...
Emulator 2019emulator cannot be started.
Runtime checks completed
Build has been canceled.
Pls helppppp

Note: Hyper-V Enabled

Xamarin forms (Android) How to move between pages and retain data

$
0
0

I am developing an application where I enter some data in FirstPage . Then I use the camera to capture image. I programmatically navigate to another page and show the captured image. The user will use a button to upload the image . Then when he presses close, it comes back to first page. The issue is I am losing the keyed data and also some calculated values in the firstPage by navigating out and back in.
Following is my code in the firstPage called ProcessPage

 var imagepage = new ShowImage(imageparam.imgName,opdetailSequenceForImage);
        ////  imagepage.BindingContext = imageparam;
        App.imgDelete = false;
        //await Navigation.PushAsync(imagepage);
       // await Navigation.PushModalAsync( imagepage);
        await Navigation.PushAsync(imagepage);

Following in the showImage.xaml.cs under button Click.

 // await Navigation.PushModalAsync(new ProcessPage());
        await Navigation.PushAsync(new ProcessPage());

in App.xaml.cs
MainPage = new MainPage(); //changed 29/03/19 for navigation
// MainPage = new NavigationPage(new MainPage());

I want to control the flow. The current flow is as 1) MainPage 2) ProductPage (Based on MainPage selection) 3)ProcessPage 4)ShowImage
From ShowImage to ProcessPage. From ProcessPage to MainPage even if the user has come from ProductPage.
How to achieve this.
Thanks in advance

How to deal with font size in Xamarin forms ?

$
0
0

Hi,

Can someone tell me how to deal with font size issues in Xamarin forms which should work on Android & iOS both (mobile & tablet) ?

I found so many solutions on forums. But i didn't found what i am looking for.

I am looking for a solution where i can define font size using styles. Generally we see in HTML5, we have font size units which is responsive for each browser and screen size. I am looking for similar kind of solution.

I have already tried it. But this is good in mobile, not in table.

<StackLayout HorizontalOptions="Center" VerticalOptions="Center">
        <Label Text="Hello, Default World !" FontSize="Default" />
        <Label Text="Hello, Large World !" FontSize="Large" />
        <Label Text="Hello, Medium World !" FontSize="Medium" />
        <Label Text="Hello, Micro World !" FontSize="Micro" />
        <Label Text="Hello, Small World !" FontSize="Small" />
</StackLayout>

Few people suggested Xlab FontManager, but it seems this is out dated now.

Please suggest me.

How can I run my Android app in Rooted emulator?

$
0
0

Hi there,

I need to access files of my app that I'm wokring on, but the emulator doesnot have root, so I cannot browse my own db.

I need to ron the emulator as rooted.

Grey line at top of form

$
0
0

Hi all, I'm displaying a header, body and footer in my form using StackLayouts with VerticalOptions set to Start, CenterAndExpand and End respectively. I set the containing StackLayout's background colour to the blue I need, the background colour for the header to white as needed, but I have a grey single pixel line above my header that I can't figure out how to remove:

The following is the basic layout of my xaml, excluding repetitive body content for brevity:

<ContentPage.Content>
    <StackLayout BackgroundColor="{StaticResource MainBackgroundColor}" >
        <StackLayout BackgroundColor="{StaticResource HeaderBackgroundColor}"
                     VerticalOptions="Start">
            <Image Source="BunBuneeLogo.png" 
                   BackgroundColor="Transparent"/>
        </StackLayout>
        <StackLayout VerticalOptions="CenterAndExpand">
            <ScrollView>
                <StackLayout>
                    <Label Text="{Binding Seasons[0].Name}" 
                           Style="{StaticResource SeasonTitleStyle}"/>

                    <controls:HorizontalListView2 ListOrientation="Horizontal"
                                                 ItemsSource="{Binding Seasons[0].Episodes}"
                                                 SelectedCommand="{Binding EpisodeSelectedCommand}">
                        <controls:HorizontalListView2.ItemTemplate>
                            <DataTemplate>
                                <templates:EpisodeItemTemplate/>
                            </DataTemplate>
                        </controls:HorizontalListView2.ItemTemplate>
                    </controls:HorizontalListView2>

                </StackLayout>
            </ScrollView>
        </StackLayout>
        <StackLayout VerticalOptions="End">
            <Image Source="BunBuneeFooter.png" 
                   BackgroundColor="Transparent"/>
        </StackLayout>
    </StackLayout>
</ContentPage.Content>

Can anyone suggest what might be causing this rogue line of pixels?

how to display multiple permissions at once in xamarin.forms

$
0
0

I want to show runtime permission popup for camera and location when the app starts or after splash screen. I am using the NuGet package: https://github.com/jamesmontemagno/PermissionsPlugin

I tried the below code on button click event.

private async void Button_Clicked(object sender, EventArgs e)
    {
        await GetPermissions();
    }


public static async Task<bool> GetPermissions()
    {
        bool permissionsGranted = true;

        var permissionsStartList = new List<Permission>()
        {
            Permission.Location,
            Permission.LocationAlways,
            Permission.LocationWhenInUse,
            Permission.Storage,
            Permission.Camera
        };

        var permissionsNeededList = new List<Permission>();
        try
        {
            foreach (var permission in permissionsStartList)
            {
                var status = await CrossPermissions.Current.CheckPermissionStatusAsync(permission);
                if (status != PermissionStatus.Granted)
                {
                    permissionsNeededList.Add(permission);
                }
            }
        }
        catch (Exception ex)
        {
        }

        var results = await CrossPermissions.Current.RequestPermissionsAsync(permissionsNeededList.ToArray());

        try
        {
            foreach (var permission in permissionsNeededList)
            {
                var status = PermissionStatus.Unknown;
                //Best practice to always check that the key exists
                if (results.ContainsKey(permission))
                    status = results[permission];
                if (status == PermissionStatus.Granted || status == PermissionStatus.Unknown)
                {
                    permissionsGranted = true;
                }
                else
                {
                    permissionsGranted = false;
                    break;
                }
            }
        }
        catch (Exception ex)
        {
        }
        return permissionsGranted;
    }

How to find an item inside a Grid inside a StackLayout inside a Template

$
0
0

Hi,

I have below ImageEditorMyPhoto

I'd like to know how can I reach it using FindByName?

It's placed inside a Grid inside a StackLayout inside a Template

<?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:SyncfusionBorder="clr-namespace:Syncfusion.XForms.Border;assembly=Syncfusion.Core.XForms"
    xmlns:SyncfusionPopup="clr-namespace:Syncfusion.XForms.PopupLayout;assembly=Syncfusion.SfPopupLayout.XForms"
    xmlns:SyncfusionImageEditor="clr-namespace:Syncfusion.SfImageEditor.XForms;assembly=Syncfusion.SfImageEditor.XForms"
    x:Class="Zeera.MyProfile">
    <ContentPage.Resources>
        <ResourceDictionary>
            <DataTemplate x:Key="MyPhotoTemplate">
                <ContentView BackgroundColor="White" x:Name="MyPhotoContentView">
                    <StackLayout x:Name="StackLayoutMyProfile">
                        <Grid x:Name="GridMyProfile" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Padding="15">
                            <SyncfusionImageEditor:SfImageEditor x:Name="ImageEditorMyPhoto" Source="{Binding Image}">
                                <SyncfusionImageEditor:SfImageEditor.ToolbarSettings>
                                    <SyncfusionImageEditor:ToolbarSettings IsVisible="false" />
                                </SyncfusionImageEditor:SfImageEditor.ToolbarSettings>
                            </SyncfusionImageEditor:SfImageEditor>
                        </Grid>
                    </StackLayout>
                </ContentView>
            </DataTemplate>
        </ResourceDictionary>
    </ContentPage.Resources>
.......................
.......................
.......................
.......................

Thanks,
Jassim


Binding updating issue with ListView?

$
0
0

Hello again!

I need to be very quick, so sorry if this has been answered or the lack of code.

I did a ListView, and set the ItemSource with a Binding to a list on the view model (groupedList). Ok, fine, it works perfectly, with grouping, etc.
I added to the ViewCell a converter to set the background color according to a boolean variable I create called "IsSelected".
Ok, it's still working, and I can get the "selected" items from the list.

The problem came when I used the "updating" command on my ViewModel

        List<MyModel> tempList = await WebApiData.GetList();

        if (tempList != null)
        {
            allList = new ObservableCollection<MyModel>(tempList);
            groupedList = new ObservableCollection<GroupList>(GroupModels(tempList));
        }
        else
        {
            if (allList != null)
                allList.Clear();
            if (groupedList != null)
                groupedList.Clear();
        }

If I had selected some elements, and refresh the page, in the ViewModel, both lists (allList and groupedList) are updated correctly with no elements selected. But the ListView is showing the previous elements selected, and no change made in the View is taking effect in the ViewModel.

I figured out that the ViewModel is not refreshing the list, and is still using the old one, so I have both (old and new) in memory: one in the ViewModel, and the other in the ViewList.
To check it, I moved the clear sentences before the IF clause, to delete the old lists before adding the new ones. And it worked perfectly. It's like Binding or ListView didn't noticed about the change of list, unless the old list get modified or deleted.

Am I right? Did I miss something? Is because I'm using Xamarin 4.10.0.448?

Thank you!

Remove page from Navigation

$
0
0

In my app structure is like below,
List Page -> Detail Page -> Edit Page

and in edit page there is button "Delete" which removes data from database.

Now my problem is to navigate user from Edit page to List Page,

I'm using Navigation.popasync 2 times for this, but on detail page i'm getting error from service that no such record exist.

How can i properly navigate user from Edit page to list page?

Xam.Plugin.TabView Orientaion Issue

$
0
0

I m using Xam.Plugin.TabView for TabControl in my Forms Application,I have faced orientaion issue while using Tabview

Sample Code:
ColorsView ContentView:



        </StackLayout>

        <StackLayout HeightRequest="335" x:Name="white" BackgroundColor="White" HorizontalOptions="FillAndExpand">

        </StackLayout>

        <StackLayout HeightRequest="245" x:Name="Green" BackgroundColor="Green" HorizontalOptions="FillAndExpand">

        </StackLayout>


        <StackLayout HeightRequest="255" x:Name="Blue" BackgroundColor="Blue" HorizontalOptions="FillAndExpand">

        </StackLayout>
    </StackLayout>
</ScrollView>

InCode Behind I am using

public XamlSamplePage()
{
InitializeComponent();

        TabViewControl tabView1 = new TabViewControl();
        TabItem tabItem = new TabItem("One", new ColorsView());
        TabItem tabItem2 = new TabItem("Two", new ColorsView());

        tabView1.ItemSource.Add(tabItem);
        tabView1.ItemSource.Add(tabItem2);

        this.Content = tabView1;
    }

In Portrait Mode

After Change the Orientation

Unable to scroll well

Unfocused Event Not Firing on User Control

$
0
0

I created a simple Xamarin Forms user control based on a ContentView. Since the ContentView is (ultimately) a VisualElement, I assumed the built-in Unfocused event would work as expected. However, while I can subscribe to my user control's Unfocused event, the event never fires. The Xamarin documentation for the Xamarin.Forms.VisualElement.Unfocused event is cryptic:

 This event is not bubbled through the Forms stack and is received directly from the native control.

Is this suggesting that I need to implement the Unfocused event explicitly within my user control?

iOS - Page's OnAppearing not called when moving the application from background to foreground?

$
0
0

Steps:

  1. Navigate to a specific page.
  2. OnAppearing is called.
  3. Move the application to background.
  4. Move the application to foreground.
  5. The page's OnAppearing method is not being called.

It does not happen to me on Android. only iOS.

Any idea? Thanks.

Viewing all 76418 articles
Browse latest View live




Latest Images