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

The name does not exist in current context [error]

$
0
0

I have a custom cell with a stack layout [with a label and a image button] in a list view when im trying to change the isVisibility of image button iam getting this error.
<?xml version="1.0" encoding="UTF-8"?>

<MasterDetailPage.Master>

        <ContentPage.Content >

               <ListView x:Name="list_menuPage" >
                    <ListView.ItemTemplate>
                        <DataTemplate>                            
                           <ViewCell>
                                <StackLayout x:Name="ChildItems" Orientation="Horizontal">
                                    <Label Text="{Binding NAME}" TextColor="Navy" HorizontalOptions="StartAndExpand"/>
                                    <ImageButton Source="right_arrow.png" IsVisible="{Binding IsSelected}" x:Name="subListButton" HorizontalOptions="EndAndExpand" Margin="5,10" Clicked="Handle_Clicked"/>
                                </StackLayout>
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                  </ListView>

            </ContentPage.Content>

        </ContentPage>
    </MasterDetailPage.Master>

<MasterDetailPage.Detail >
    <ContentPage Padding="10" BackgroundColor="Green">


        </ContentPage>
    </MasterDetailPage.Detail>

using System;
using System.Collections;
using System.Collections.Generic;
using Newtonsoft.Json;
using Xamarin.Forms;

namespace LoginPage
{
public partial class Menu : MasterDetailPage
{
private const string Url = "http://techportsolutions.myddns.me:45152/eKontenService/RestServiceImpl.svc/getServiceData?InputData={0}";
private System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();

    public Menu()
    {
        InitializeComponent();
        getMenu();
        //list_menuPage.ItemTemplate = new DataTemplate(typeof(Models.SubListCell));


    }
    public List<Models.MenuDetails> originalList;
    public List<Models.MenuDetails> topMenuItems;


    async public void getMenu()
    {
        var parameters = new Dictionary<String, String>();
        parameters["iFKCompanyID"] = "20";
        parameters["iFKUserID"] = "55";
        parameters["FK_DOCUMENT_TYPE_ID"] = "0";
        parameters["iFKSalesmanID"] = "0";
        parameters["iFKActorTypeID"] = "0";
        parameters["sAPITemplate"] = "GETROLEMENUS";
        parameters["sAPIValues"] = "|||";
        var menuArray = new List<Dictionary<string, string>>
        {
            parameters
        };
        string obj = JsonConvert.SerializeObject(menuArray, Formatting.Indented);
        var content = await client.GetStringAsync(string.Format(Url, obj));
        originalList = JsonConvert.DeserializeObject <List<Models.MenuDetails>> (content);

        if(originalList!=null)
        {
           topMenuItems = originalList.FindAll(s => s.IS_TOP_MENU == true && s.FK_PARENT_MENU_ID == null);
            list_menuPage.ItemsSource = topMenuItems;
        }


    }

    void Handle_Clicked(object sender, System.EventArgs e)
    {
        if (subListButton.IsVisible == true) // here im trying to use that and facing issue
        {

        }

    }
}

}


TabbedPage and Globale Variables ?

$
0
0

Hi devs !

I have a Tabbed Page where each page is a separate class but I have to transit informations between my pages.
what is the best way to do this ?

Thanks ;)

Xamarin Form 4.0, Shell hamburger Icon

$
0
0

Hello,

How can I add "hamburger.png" icon for iOS and UWP app with the shell flyout ?

Thanks.

Custom Renderer for Picker automatically changes layout in app (without overrides)

$
0
0

I wanted to make a custom renderer for the Picker because it doesn't re-measure it's width according to the SelectedIndex and managed to do that with this (sneaky) renderer:

using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using DigitalFleetTool.Droid.Renderers;
using System.ComponentModel;

[assembly: ExportRenderer(typeof(Picker), typeof(CustomPickerRenderer))]
namespace DigitalFleetTool.Droid.Renderers
{
    public class CustomPickerRenderer : PickerRenderer
    {

        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {

            base.OnElementPropertyChanged(sender, e);
            if (e.PropertyName.Equals("SelectedIndex"))
            {
                var picker = (Picker)sender;


                IVisualElementRenderer view = Platform.GetRenderer(picker);
                view.ViewGroup.SetMinimumWidth(1);

            }
        }

    }
}

However, I noticed it changed the layout of the Spinner from the Xamarin default spinner to what seems to be the Android default spinner. I like the Xamarin one because it can display all options at once in my app which makes it easier to use, so I removed the override (so it basically contains no code) but it STILL changes the Spinner! The largest problem is that the spinner it changes to doesn't seem to be reachable through the Control parameter and it's partly transparent (unusable) in my emulators. It seems to work on my real device, but I don't trust it to work on all devices after seeing it on the emulator.
Image of the Xamarin spinner http://imgur.com/a/bQJtA
Image of the Android spinner http://imgur.com/a/Jqnly

How take a SkiaSharp SKData and write out a pdf?

$
0
0

Our app uses SkiaSharp and Xamarin Forms to create sketches. We can take a completed sketch and write it out as a jpg.
SKData skData = surface.Snapshot().Encode(); using (Stream stream = File.Open(fileout, FileMode.OpenOrCreate, System.IO.FileAccess.Write, FileShare.ReadWrite)) { skData.SaveTo(stream); }

How do I write it out as a pdf?

One step is to create an SKDocument like this:
SKDocument skDocument = SKDocument.CreatePdf(SKWStream, dpi);
How do I turn the SKData into an SKWStream?

Thanks for having a look at this.

Disable tabbed page swiping when using FormsAppCompatActivity

ADMob not show in Android - Xamarin forms

$
0
0

Good Morning,

I Have a solution app in xamarin forms, and I need add ADMOB, and I do this, but, my ad not show, please help me:

My AdMob work:

I use plugin: Xamarin.GooglePlayServices.Ads - Version: 60.1142.1 - the last version.

MainActivity onCreate, My row of initialize MobileAd:
MobileAds.Initialize(ApplicationContext, "ca-app-pub-xxxxxxxxxxxxxxxxx~xxxxxxxxxx"); I tryed with ID: "xxxxxxxxxxxxxxxxxxxxxxxxxxx/xxxxxxxxxx", but I not have success

My ADMobView class:

 **public class AdMobView : View
 {
 }**

My AdMobRenderer:

    ** [assembly: ExportRenderer(typeof(AdMobView), typeof(AdMobViewRenderer))]
     namespace Anuncie.Droid.Renderes
     {
         public class AdMobViewRenderer : ViewRenderer<AdMobView, AdView>
         {
             public AdMobViewRenderer(Context context) : base(context) { }

             string adUnitId = string.Empty;
             //Note you may want to adjust this, see further down.
             AdSize adSize = AdSize.SmartBanner;
             AdView adView;
             AdView CreateNativeAdControl()
             {
                 if (adView != null)
                     return adView;

                 // This is a string in the Resources/values/strings.xml that I added or you can modify it here. This comes from admob and contains a / in it
                 adUnitId = "xxxxxxxxxxxxxxxxxxxxxxxxxxx/xxxxxxxxxx"; I tryed with ca-app-pub-xxxxxxxxxxxxxxxxx~xxxxxxxxxx, but I not have success
                 adView = new AdView(Forms.Context);
                 adView.AdSize = adSize;
                 adView.AdUnitId = adUnitId;

                 var adParams = new LinearLayout.LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent);

                 adView.LayoutParameters = adParams;

                 adView.LoadAd(new AdRequest
                                 .Builder()
                                 .Build());
                 return adView;
             }

             protected override void OnElementChanged(ElementChangedEventArgs<AdMobView> e)
             {
                 base.OnElementChanged(e);
                 if (Control == null)
                 {
                     if (Control == null)
                     {
                         CreateNativeAdControl();
                         SetNativeControl(adView);
                     }
                 }
             }
         }
     }**

Thanks

Sqlite best practice - single DB connection for app or open/close connection for each operation?

$
0
0

Hi,
I've seen various coding samples where people either open and hold a SqliteConnection for the life of the app and others were the SqliteConnection is opened and closed. The Sqlite documentation indicates that there is a SERIALIZED threading mode that makes sharing a connection between threads safe.
Does anyone have experience using that in Xamarin Forms? I'll have background threads updating the database at the same time as the UI threads.
Should I obtain SqliteConnection and open/close it with every operation or leave the SqliteConnection open the life of the app?


"File is corrupted" error when trying to install .apk file in Android

$
0
0

Hello all, I've looked around the forums for an answer to this problem but all I've seen are references to old bugs which should've been fixed by now. I've finished preparing a test version of an android app using Xamarin and I'd like to test it on my phone. The application runs just fine when I connect my phone to the computer and I debug with it, but when distributing the APK and installing it the error mentioned in the title pops up.

These are the fixes I've tried to get it working:

Unchecking Shared Runtime/Fast Deployment
Clean/Rebuild/remaking the archived .apk file
Enable and disabling linking, proguard, multidex
Making and remaking Ad-hoc identities

Nothing's worked so far. I'm leaning towards it being a signing issue from what I've read since the application runs perfectly fine in debugging mode.

How can I create a radio button control

$
0
0

Dear experts,

I am new to Xamarin.Forms. I just realized that Xamarin has no radio button control out of the box. Could you please refer me to a place where I could get one?

I cannot afford paying thousands to buy it from Syncfusion.
Also, I looked at http://bsubramanyamraju.blogspot.com/2018/03/how-to-create-radiobutton-in_13.html. This one seems simple enough, but no images provided. Another one I found was too complicated for me.

Please advise.

Text wrapping issue on android

$
0
0

Hello,

I am working on a chat application and using frame to create a chat bubble around chats. I am facing problem as text wrapping on label is goofy. I had tried different things like layout changes but it doesn't work.

I am using xamarin forms and with the same code the issue is not with iOS. It only exist in Droid devices. I am sharing the code and screenshot of issue below.

Please note that the code I am sharing is for receiving chat.

The code is as follows:

<Grid ColumnSpacing="2" Padding="5">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="40" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Grid.Resources>

                <ResourceDictionary>
                    //Resources goes here
            </Grid.Resources>

            <Frame Grid.Row="0" OutlineColor="Transparent" Margin="5,0" Padding="8" VerticalOptions="StartAndExpand" HorizontalOptions="StartAndExpand" Grid.Column="0" BackgroundColor="#F5F4F9">
                <StackLayout>
                    <Label TextColor="#4a4a4a" Text="{Binding Text,Converter={StaticResource DecodeString}}" LineBreakMode="WordWrap">
                        <Label.FontSize>
                            <OnPlatform x:TypeArguments="x:Double" Android="15" iOS="16" />
                        </Label.FontSize>
                    </Label>
                </StackLayout>
            </Frame>

            <Label FontSize="Micro" Margin="8,0" HorizontalOptions="Start" Grid.Row="1" Grid.Column="0" Text="{Binding Time, Converter={StaticResource convertTime}}" TextColor="Gray" />
        </Grid>

In the sreenshot you can see that the extra space is occupied by label. This is not happening in iOS. Is there a way to solve the issue on droid. Any help is appreciated.

HttpClient - Unable to write data to the transport connection: The socket has been shut down.

$
0
0

Hello,

I was given an application to debug lately and I encountered an error while sending a json. This request uses HttpClient, the content of the sending is 18Mb and contains 88 photos in base 64 in an HTML structure, in JSON. On the server, the php.ini is configured to accommodate requests of 100Mb max, so I do not think the error comes from the server.
The application makes a post data and throws an exception to the middle of the mailing.

Code:

        if (client.BaseAddress == null)
        {
            client.BaseAddress = new Uri(App.CommonDatas.API_URI);
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            client.DefaultRequestHeaders.Add("Computer-id", CrossDeviceInfo.Current.Id);
        }

        if(!prevent_token && (need_token || app.token != null))
        {
            client.DefaultRequestHeaders.Remove("X-Token");
            client.DefaultRequestHeaders.Add("X-Token", app.token);
        }
        response = await client.PostAsync(path, new StringContent(jsonData))

StackTrace:

+       e   {System.Net.Http.HttpRequestException: An error occurred while sending the request ---> System.IO.IOException: Unable to write data to the transport connection: The socket has been shut down. ---> System.Net.Sockets.SocketException: The socket has been shut down
  at System.Net.Sockets.Socket.EndSend (System.IAsyncResult asyncResult) [0x00012] in <3e9b3e26c4694baab3f689687ad40612>:0 
  at System.Net.Sockets.NetworkStream.EndWrite (System.IAsyncResult asyncResult) [0x00057] in <3e9b3e26c4694baab3f689687ad40612>:0 
   --- End of inner exception stack trace ---
  at System.Net.Sockets.NetworkStream.EndWrite (System.IAsyncResult asyncResult) [0x0009b] in <3e9b3e26c4694baab3f689687ad40612>:0 
  at System.IO.Stream+<>c.<BeginEndWriteAsync>b__53_1 (System.IO.Stream stream, System.IAsyncResult asyncResult) [0x00000] in <fe08c003e91342eb83df1ca48302ddbb>:0 
  at System.Threading.Tasks.TaskFactory`1+FromAsyncTrimPromise`1[TResult,TInstance].Complete (TInstance thisRef, System.Func`3[T1,T2,TResult] endMethod, System.IAsyncResult asyncResult, System.Boolean requiresSynchronization) [0x00000] in <fe08c003e91342eb83df1ca48302ddbb>:0 
--- End of stack trace from previous location where exception was thrown ---
  at Mono.Net.Security.MobileAuthenticatedStream+<InnerWrite>d__67.MoveNext () [0x000d3] in <3e9b3e26c4694baab3f689687ad40612>:0 
--- End of stack trace from previous location where exception was thrown ---
  at Mono.Net.Security.AsyncProtocolRequest+<ProcessOperation>d__24.MoveNext () [0x00196] in <3e9b3e26c4694baab3f689687ad40612>:0 
--- End of stack trace from previous location where exception was thrown ---
  at Mono.Net.Security.AsyncProtocolRequest+<StartOperation>d__23.MoveNext () [0x0008b] in <3e9b3e26c4694baab3f689687ad40612>:0 
--- End of stack trace from previous location where exception was thrown ---
  at Mono.Net.Security.MobileAuthenticatedStream+<StartOperation>d__58.MoveNext () [0x001bf] in <3e9b3e26c4694baab3f689687ad40612>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Net.WebRequestStream+<ProcessWrite>d__33.MoveNext () [0x00270] in <3e9b3e26c4694baab3f689687ad40612>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Net.WebRequestStream+<WriteAsyncInner>d__32.MoveNext () [0x001aa] in <3e9b3e26c4694baab3f689687ad40612>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Net.Http.HttpClientHandler+<SendAsync>d__64.MoveNext () [0x0036e] in <25ebe1083eaf4329b5adfdd5bbb7aa57>:0 
   --- End of inner exception stack trace ---
  at System.Net.Http.HttpClientHandler+<SendAsync>d__64.MoveNext () [0x00489] in <25ebe1083eaf4329b5adfdd5bbb7aa57>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Net.Http.HttpClient+<SendAsyncWorker>d__49.MoveNext () [0x000ca] in <25ebe1083eaf4329b5adfdd5bbb7aa57>:0 
--- End of stack trace from previous location where exception was thrown ---
  at Oracio.WebServices+<PostPutAsync>d__6`1[T].MoveNext () [0x007cb] in C:\oracio\android-old\Oracio\Classes\WebServices.cs:209 }  System.Net.Http.HttpRequestException

I can not provide you with json, it is private but I can validate that besides its size it is valid.
If you need information, for versions of packages for example, I am at your disposal.
I thank you in advance.

Xamarin Forms Map Direction

$
0
0

Xamarin forms maps Direction draws only straight lines, but i need to draw on road instead of straight lines

Please tell me how to resolve this?

Listview Selected Item Background Color

$
0
0

Is it possible to set the ListView selected item background color? Right now on IOS its gray and I want it to be transparent if possible.

Tree View in Xamarin forms.

$
0
0

Hello guys,
Is there any way to implement Tree View in Xamarin forms ? If yes then please let me know how ?

Thank you.


Decryption Unsuccessful Message

$
0
0

I am attempting to run the HELLO, ANDROID; QUICKSTART.

After I follow the instruction: RUN THE APP. Test the application by running it on an Android device or emulator. When I click ANDROID-ACCELATED-X86 I get this message DESCRYPTION UNSUCCESSFUL The password you entered is correct, but your data is corrupt. To resume using the phone, you need to perform a factory reset. When you set up your phone after the reset, you will have an opportunity to restore data that was backed up to your goggle account. What steps should I take. I need help on this matter.

Device.OpenURI not working on Android 9?

$
0
0

I had a user complain that a button wasn't working in my app. All the button does is calls Device.OpenURI() to open a website in the system browser. I loaded up my app in an Android 9 emulator, and sure enough, it doesn't open anything. I tried searching the forums and didn't see anything. Has anyone else had a problem with this?

BLOB to Image Binding

$
0
0

I have to bind images from a SQLite database. The images are stores as BLOB (png file).

var image = new Image
 {
          HorizontalOptions = LayoutOptions.Start,
          WidthRequest = 40,
          HeightRequest = 40
 };

 var bnd = new Binding("Image", BindingMode.Default, new ArrayToImageConverter());
 image.SetBinding(Image.SourceProperty, bnd);

How to define an "ArrayToImageConverter"

        public abstract class ArrayToImageConverter : IValueConverter
            {
               public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
               {
                     byte[] bmp = value as byte[];
                     if (bmp == null)
                         return null;

                   return new StreamImageSource 
                   {
                         Stream =  ?????
                    };
               }
                public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
               {
                     throw new System.NotImplementedException();
                }
            }

popup location

$
0
0

I have a little popup (a stacklayout with a few controls) that I would like to show when I double click on an Entry. I got the double click to work but now would like the popup to show right above the entry control that was clicked on. How can I set the location of my popup to be by my entry control? My stacklayout is inside of a AbsoluateLayout so not sure if I use the AbsoluteLayout.SetLayoutBounds() to set the exact location of the popup? The popup can vary in location being there can be many Entry controls in a grid. So somehow I need to get the location of the entry control and use that to set the location of the popup.

XF - Android - SMS and Call Log Permissions violation. (Not in manifest)

$
0
0

I have an app built in Xamarin.Forms and I'm in the middle of publishing to the stores,

iOS version is already approved.
Android, ** approved **then **removed ** by:

Violation of the Permissions policy
SMS and Call Log Permissions are subject to additional restrictions.....

and they have these options:
Option 1) If your app does not require access to Call Log or SMS permissions:
Option 2) If your app’s use case is not eligible but you require additional time to make the necessary changes to your app
Option 3) If your app is a default handler, or you believe your app qualifies for an exception

the weird thing here is, I don't request any of those permissions at all, my app neither send/receive sms, or read/write call logs or perform calls and I don't have anything regarding these permissions in my Manifest nor the merged Manifest

what I do have in my Android Manifest is the following:

        <permission android:name="com.myapp.xamarin.permission.C2D_MESSAGE" android:protectionLevel="signature" />
            <uses-permission android:name="android.permission.USE_FINGERPRINT" />
            <uses-permission android:name="com.samsung.android.providers.context.permission.WRITE_USE_APP_FEATURE_SURVEY" />
            <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
            <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
            <uses-permission android:name="android.permission.WAKE_LOCK" />
                <uses-permission android:name="com.myapp.xamarin.permission.C2D_MESSAGE" />
            <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
            <uses-permission android:name="android.permission.INTERNET" />
            <uses-permission android:name="android.permission.GET_ACCOUNTS" tools:node="remove" />
            <application android:label="My App Name" android:icon="@drawable/icon">
                <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" />
                <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND">
                    <intent-filter>
                        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                        <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
                        <category android:name="com.myapp.xamarin" />
                    </intent-filter>
                </receiver>
                <meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/icon_pn" />
            </application>

so, yes, I'm using Xamarin.Firebase to perform push notifications in my app, so, I don't know if internally is requesting those permissions or something,
or how the 'GET_ACCOUNTS' permissions is added after the manifest merge,

I already tried, removing manually all those permissions from the manifest, following this: https://support.hockeyapp.net/kb/client-integration-android/hockeyapp-for-android-sdk#4-7-1-removing-external-storage-permission

which basically is adding this in the manifest:
<uses-permission android:name="android.permission.READ_SMS" tools:node="remove" />

does anyone have any idea on how to approach this issue, I've also been looking into the documentation of all 3rd party libraries that I have, to see if there's something regarding these permissions but no luck so far,

any idea, comment will be much appreciated,

thanks folks!

Viewing all 77050 articles
Browse latest View live


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