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

Is there a "New"!? or "Best"!? local storage solution for Xamarin.Forms cross platform apps?

$
0
0

Since... forever, there is the one and only local storage solution for Xamarin.Forms cross platform apps, Sqlite, which can store fairly large amount of data, 10s of thousands records at least, with very good performance.

That's my understanding.

I'm really hoping there is a new-ish solution other than Sqlite, which local storage solution do you use, and which one do you prefer?

Thanks.


how to use frame in a grid?

$
0
0

how to use frame in a grid?
please can you show me a code sample for xaml?

I need a grid with borders

boxview or frame is better and how???

I expect to get an infinite loop when I implement IValueConverter but there isn't.

$
0
0

I have an Entry text which is binded in TwoWay mode to a simple string.
In Convert() I add the letter "S" ("for came from Source")
In ConvertBack() I add the letter "T" ("for came from Target").

Now, when I write something in the entry (lets say I write the string "A"), I expect the next phases to occur:
1. The Target was changed, so ConvertBack() should be called, and send the string AT to the source (Because the converter adds "T").
2. Therefore the Source was changed, so Convert() should be called and send the string ATS to the Target (Because the converter adds "S")..
3. Therefore the Target was changed, so ConvertBack() should be called, and send the string ATST to the source.
4. Therefore the Source was changed, so Convert() should be called and send the string ATSTS to the Target.
5. and on and on and on......Endlessly.

Of some reason It doesn't happen ( ConvertBack() is being called, then Convert() is being called and that's it).

Why isn't an infinite loop over here?

This is the converter:

public class NiceConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string resultAfterConvert = value as string + "S";
            return resultAfterConvert;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string resultAfterConvert = value as string + "T";
            return resultAfterConvert;
        }
    }

Email reciever

$
0
0

Hi,
I would like to recieve mail in my application. I found a NuGet Library called MailKit.
The problem is that after starting the application it locks on the ssl certificate.

public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();
            using (var client = new ImapClient())
            {
                client.Connect("imap.gmail.com", 993, true);

                client.Authenticate("test@test.it", "pass");

                // The Inbox folder is always available on all IMAP servers...
                var inbox = client.Inbox;
                inbox.Open(FolderAccess.ReadOnly);

                Console.WriteLine("Total messages: {0}", inbox.Count);
                Console.WriteLine("Recent messages: {0}", inbox.Recent);

                for (int i = 0; i < inbox.Count; i++)
                {
                    var message = inbox.GetMessage(i);
                    Console.WriteLine("Subject: {0}", message.Subject);
                }

                client.Disconnect(true);
            }
        }
    }

the error is:

MailKit.Security.SslHandshakeException: 'An error occurred while attempting to establish an SSL or TLS connection.

The server's SSL certificate could not be validated for the following reasons:
• Ssl error:1000007d:SSL routines:OPENSSL_internal:CERTIFICATE_VERIFY_FAILED
at /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/boringssl/ssl/handshake_client.c:1132
'

Thankou in advance,
David.

Howto change glyph of fontimagesource via datatrigger

$
0
0

Hy,
i want to create an Expander that shows the Expander state with an Image.

The code snippet that i found works with an Image and that worked well. But i want to use fontawesome and so i use a fontimagesource.
So now i need to change the glyph of the fontimagesource and don´t know how.

here is my XAML:

<Image
     HeightRequest="20"
     HorizontalOptions="End"
     VerticalOptions="Start"
     WidthRequest="20">
     <Image.Source>
          <FontImageSource
               FontFamily="{StaticResource FontAwesomeSolid}"
               Glyph="{x:Static fontawesome:FontAwesomeIcons.AngleDown}"
               Size="20"
               Color="Gray" />
     </Image.Source>
     <Image.Triggers>
          <DataTrigger
               Binding="{Binding Source={RelativeSource AncestorType={x:Type Expander}}, Path=IsExpanded}"
               TargetType="Image"
               Value="True">
               <Setter Property="**Glyph???**" Value="{x:Static fontawesome:FontAwesomeIcons.AngleUp}" />
          </DataTrigger>
     </Image.Triggers>
</Image>

Xamarin.Essentials Permissions.RequestAsync() Doesn't Return Status

$
0
0

Xamarin.Essentials Permissions.RequestAsync<Permissions.LocationWhenInUse>() doesn't return Status after user interaction.

If Location has not yet been approved, calling

status = await Permissions.RequestAsync<Permissions.LocationWhenInUse>();

will open Android Dialog to approve using location. When the user approves "Allow Only While Using The App" this call does NOT return to the next line of code with the status set.

Why is this??? I would expect that the status should contain status == PermissionStatus.Granted and the next line of code should be hit.

Toolbar item overflow icon always shown white ?

$
0
0

Toolbar item overflow icon always shown white ? why you think any idea thanks..

Does Xamerin have something like WindowsFormsHost? Need Unity3D inside Xamerin.Forms

$
0
0

I want to run separate process inside a frame in Xamerin.Forms app. Something like this can be done with WPF using WindowsFormsHost or HwndHost.

Again I am talking about a separate process, I understand that the 2 processes would have to interact with some cross process way etc. My only question is can I run a separate process inside a frame inside a Xamerin.Forms app


Bindable Layout Toggle Checkbox

$
0
0

I have a StackLayout with a BindableLayout. In the DataTemplate, I have a simple StackLayout with a Checkbox as one of it's children. Is there some XAML mechanism available for toggling the child checkbox when the user taps the parent StackLayout using it's Tap Gesture Recognizer?

The part I'm struggling with is the fact that they are "dynamic" items inside of a data template, else I could just hard code the command bindings. I've looked at Behaviors and Triggers, but am struggling with understanding how they might be useful in this situation? I could just attach a handler to the Tap Gesture Recognizer in the codebehind and locate the specific StackLayout's child checkbox and toggle it, but that doesn't seem like a great solution since the hierarchy of the DataTemplate could change in the future.

Edit: Additional Info, the DataTemplate represents an IList of models available in a view model. The checkbox is bound 2-way to a boolean property in that model

how to send httpcontent then the controller will get the parameters?

$
0
0

I am sending post request to controller

HttpClient client=new HttpClient();
var content = new ByteArrayContent(Encoding.UTF8.GetBytes("{\"action\":\"getProductType\"}"));
content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
var response = await client.PostAsync("Product", content);

the controller:

public async Task Post(string action){

}

but the controller can not get the value of action

cant deploy my project on my phone anymore, works on my friends though

$
0
0


Severity Code Description Project File Line Suppression State Error ADB1000: Deployment failed Xamarin.AndroidTools.AndroidDeploymentException: InternalError ---> System.InvalidOperationException: Could not determine the installation path for package com.companyname.app9.adb shell pm path com.companyname.app9returned ''. --- End of inner exception stack trace --- at AndroidDeviceExtensions.<GetPackageRemotePathAsync>d__39.MoveNext() in C:\A\_work\115\s\External\androidtools\Xamarin.AndroidTools\Devices\AndroidDeviceExtensions.cs:line 672 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at AndroidDeviceExtensions.<GetFastDevRemotePathAsync>d__44.MoveNext() in C:\A\_work\115\s\External\androidtools\Xamarin.AndroidTools\Devices\AndroidDeviceExtensions.cs:line 737 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Xamarin.AndroidTools.AndroidDeploySession.<GetFastDevRemotePathAsync>d__115.MoveNext() in C:\A\_work\115\s\External\androidtools\Xamarin.AndroidTools\Sessions\AndroidDeploySession.cs:line 504 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Xamarin.AndroidTools.AndroidDeploySession.<FastDevAsync>d__114.MoveNext() in C:\A\_work\115\s\External\androidtools\Xamarin.AndroidTools\Sessions\AndroidDeploySession.cs:line 471 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) at Xamarin.AndroidTools.AndroidDeploySession.<RunAsync>d__106.MoveNext() in C:\A\_work\115\s\External\androidtools\Xamarin.AndroidTools\Sessions\AndroidDeploySession.cs:line 225 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Xamarin.AndroidTools.AndroidDeploySession.<RunLoggedAsync>d__104.MoveNext() in C:\A\_work\115\s\External\androidtools\Xamarin.AndroidTools\Sessions\AndroidDeploySession.cs:line 119 0

Which push notification integration would you recommend for Xamarin Forms in 2020?

$
0
0

Hi everyone !
I need your ideas. A few years ago, I integrated Push Notification for Xamarin Forms via AppCenter. But, then I guess the push notification service was removed from the AppCenter.

Which integration do you think I should use to send detailed push notifications for Xamarin Forms?

Thanks in Advance !

How to custom a view to make a circle checkbox and a addminus button?

$
0
0

I want to make a circle check box

and a add and minus button

how to make the view?

ContentView xaml properties not updating

$
0
0

Hello.
I've been trying to make a Calendar Control for an app I am developing.
I created a ControlView with its .xaml and I am trying to set a property in the xaml of the page that is consuming the control, like this:

<?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:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:app2="clr-namespace:App2"
             mc:Ignorable="d"
             x:Class="App2.MainPage">
    <StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Padding="0">
        <app2:CalendarControl x:Name="clControl" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" EsSemanal="True"></app2:CalendarControl>
    </StackLayout>

</ContentPage>

I set the "EsSemanal" property to true to tell the calendar to render in week mode.
My "CalendarControl" .cs:

public partial class CalendarControl : ContentView
    {
        public static readonly BindableProperty EsSemanalProperty = BindableProperty.Create(nameof(EsSemanal), typeof(bool), typeof(CalendarControl), false);
        public bool EsSemanal
        {
            get => (bool)GetValue(EsSemanalProperty);
            set => SetValue(EsSemanalProperty, value);
        }
...
}

So in the constructor I render the control:

public CalendarControl()
        {
            InitializeComponent();
            if (!EsSemanal)
            {
                //Cargamos diseño de calendario diario
                Grid gridDiaria = new Grid();
                gridDiaria.VerticalOptions = LayoutOptions.FillAndExpand;
                gridDiaria.SetValue(Grid.RowProperty, 1);
                gridDiaria.RowDefinitions.Add(new RowDefinition { Height = new GridLength(2, GridUnitType.Star) });
                gridDiaria.RowDefinitions.Add(new RowDefinition { Height = new GridLength(8, GridUnitType.Star) });
                //Label con el día
                Label lbDia = new Label();
                lbDia.HorizontalOptions = LayoutOptions.CenterAndExpand;
...
        }
    }

The problem is that when the constructor gets called, the "EsSemanal" property is still set to the default value.
It is not updating.
Is there any way of making the value update before the constructor gets called or what are some good strategies of approaching this?

Thank You.

Xamarin fails to Archive the project for publication (iOS)

$
0
0

Hello everyone,
I developed a multi-platform, it builds without any error and few warning. It runs on the device in debug mode. When I set it to Release mode and trying to archive it for publication, it throws a few warning that stops the archive.

It never happened previously that warnings crash the archive processing.

these are the warnings:

*** Found conflicts between different versions of "SQLitePCLRaw.batteries_v2" that could not be resolved.

  • Found conflicts between different versions of "SQLitePCLRaw.core" that could not be resolved.
  • Found conflicts between different versions of "System.Net.Http" that could not be resolved.
  • Found conflicts between different versions of "Microsoft.CSharp" that could not be resolved.
  • Found conflicts between different versions of the same dependent assembly. Please set the "AutoGenerateBindingRedirects" property to true in the project file.
  • Obsolete member 'AppDelegate.FinishedLaunching(UIApplication, NSDictionary)' overrides non-obsolete member 'UIApplicationDelegate.FinishedLaunching(UIApplication, NSDictionary)'**

How can I archive the app? Do you have any thought?

Kind regards,
Kamal


WebView Don't Fit Screen in Xamarin ios

$
0
0

I use Xamarin WebView to open a site, On Android the site fills the page and work correctly . But on iOS it appears as shown in the picture
I used this code but it does not solve the problem
var myDisplay = DeviceDisplay.MainDisplayInfo;
MyWebView.HeightRequest = myDisplay.Height;
MyWebView.WidthRequest = myDisplay.Width;

in xaml

I want webview in Ios Appear as same as Android. I added 2 picture to describe what i want
IosWebView
AndriodWebView

Network reachability not woriking in Xamarin iOS

$
0
0

Hi Team,

We are connected our app in iOS device with the help of mobile hotspot that time we switched off the mobile network but still connected wifi. That time i need to trigger the event in Xamarin.iOS project. How to achieve this.

We tried two approach in Xamarin.iOS platform oriented but it will not triggered. I mentioned Reachability class and DeviceNetworkStatus class below that we tried. Please refer and give some solution.

In appdelegate.cs we called above class and tried to trigger.

    private Reachability internetReachability;
    private Reachability hostReachability;

public override bool FinishedLaunching(UIApplication uiApplication, NSDictionary launchOptions)
{
// Reachability class approach
//const string remoteHostName = "www.google.com";
// hostReachability = Reachability.ReachabilityWithHostName(remoteHostName);
//hostReachability.StartNotifier();
//internetReachability = Reachability.ReachabilityForInternetConnection();
//internetReachability.StartNotifier();

      ** // Device Network Status approach**
        DependencyServiceImplementations.DeviceNetworkStatus.Instance.Start(); 

}

Note : Device Network Status approach we can able to triggered some mobile devices hotspot like settings available in AP Band width. Some more devices not triggered. Please kindly suggest good approach to handle my scenario.

DeviceNetworkStatus.cs
public class DeviceNetworkStatus
{
private static readonly Lazy networkStatus = new Lazy(() => new DeviceNetworkStatus());

    private  NWPathMonitor monitor;

    public static DeviceNetworkStatus Instance => networkStatus.Value;

    public  void Start()
    {
        monitor = new NWPathMonitor();

        var queue = DispatchQueue.GetGlobalQueue(DispatchQueuePriority.High);

        monitor.SnapshotHandler = (NWPath path) =>
        {
                            Debug.WriteLine(path.Status);
        };

        monitor.SetQueue(queue);
        monitor.Start();
    }

    public void Stop()
    {
        if (monitor != null)
        {
            monitor.Cancel();
            monitor.Dispose();

            monitor = null;
        }
    }
}

Reachability.cs

public enum NetworkStatus
{
NotReachable,
ReachableViaWWAN,
ReachableViaWiFi
}

/// <summary>
/// Basic demonstration of how to use the SystemConfiguration Reachablity APIs.
/// </summary>
public  class Reachability : NSObject
{
    ~Reachability()
    {
        StopNotifier();
        if (NetworkReachability != null)
        {
            NetworkReachability.Dispose();
        }
    }

    public static string ReachabilityChangedNotification { get; } = "kNetworkReachabilityChangedNotification";

    public NetworkReachability NetworkReachability { get; private set; }

    public static Reachability ReachabilityWithHostName(string hostName)
    {
        var reachability = new NetworkReachability(hostName);
        return new Reachability { NetworkReachability = reachability };
    }

    public static Reachability ReachabilityWithAddress(IPAddress hostAddress)
    {
        var reachability = new NetworkReachability(hostAddress);
        return new Reachability { NetworkReachability = reachability };
    }

    //public static Reachability ReachabilityForInternetConnection()
    //{
    //    var reachability = new NetworkReachability(new IPAddress(0));
    //    return new Reachability { NetworkReachability = reachability };
    //}

    public static Reachability ReachabilityForInternetConnection()
    {
        var reachability = new NetworkReachability("www.google.com");
        return new Reachability { NetworkReachability = reachability };
    }

    private void HandleNotification(NetworkReachabilityFlags flags)
    {
        // Post a notification to notify the client that the network reachability changed.
        NSNotificationCenter.DefaultCenter.PostNotificationName(ReachabilityChangedNotification, this);
    }

    #region Start and stop notifier

    public bool StartNotifier()
    {
        var result = false;

        var status = NetworkReachability.SetNotification(HandleNotification);
        if (status == StatusCode.OK)
        {
            result = NetworkReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
        }

        return result;
    }

    private void StopNotifier()
    {
        if (NetworkReachability != null)
        {
            NetworkReachability.Unschedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
        }
    }

    #endregion

    #region Network Flag Handling

    public NetworkStatus NetworkStatusForFlags(NetworkReachabilityFlags flags)
    {
        if ((flags & NetworkReachabilityFlags.Reachable) == 0)
        {
            // The target host is not reachable.
            return NetworkStatus.NotReachable;
        }

        NetworkStatus result = NetworkStatus.NotReachable;
        if ((flags & NetworkReachabilityFlags.ConnectionRequired) == 0)
        {
            // If the target host is reachable and no connection is required then we'll assume (for now) that you're on Wi-Fi...
            result = NetworkStatus.ReachableViaWiFi;
        }

        if ((flags & NetworkReachabilityFlags.ConnectionOnDemand) != 0 ||
            (flags & NetworkReachabilityFlags.ConnectionOnTraffic) != 0)
        {
            // ... and the connection is on-demand (or on-traffic) if the calling application is using the CFSocketStream or higher APIs...
            if ((flags & NetworkReachabilityFlags.InterventionRequired) == 0)
            {
                // ... and no [user] intervention is needed...
                result = NetworkStatus.ReachableViaWiFi;
            }
        }

        if ((flags & NetworkReachabilityFlags.IsWWAN) == NetworkReachabilityFlags.IsWWAN)
        {
            // ... but WWAN connections are OK if the calling application is using the CFNetwork APIs.
            result = NetworkStatus.ReachableViaWWAN;
        }

        return result;
    }

    public bool ConnectionRequired()
    {
        if (NetworkReachability.TryGetFlags(out NetworkReachabilityFlags flags))
        {
            return (flags & NetworkReachabilityFlags.ConnectionRequired) != 0;
        }

        return false;
    }

    public NetworkStatus CurrentReachabilityStatus()
    {
        var returnValue = NetworkStatus.NotReachable;
        if (NetworkReachability.TryGetFlags(out NetworkReachabilityFlags flags))
        {
            returnValue = this.NetworkStatusForFlags(flags);
        }

        return returnValue;
    }

    #endregion

    protected override void Dispose(bool disposing)
    {
        base.Dispose(disposing);
        if (disposing)
        {
            if (NetworkReachability != null)
            {
                NetworkReachability.Dispose();
            }
        }
    }
}

File.Create Not creating file

$
0
0

Hopefully someone can help me I have the following snippet of code:

        var backingFile = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "ThisIsATest.txt");
        bool doesExist = File.Exists(backingFile);
        using (var writer = File.CreateText(backingFile))
        {
            writer.WriteLineAsync("This is a test");
        }

This is to test if the file is created and if i can access it later on in the code the doesExist returns a true value but when i brows to it on the device (android or ios) the file does not exist.

I did add a file provider to the android-manifest in the hopes that it would solve the problem.

Any help would be appreciated.

How To post Data Xamarin.forms to Asp.net.core server

$
0
0

~~class attachment
{
public int AttachmentID { get; set; }
public int StudentID { get; set; }
public IFormFile file { get; set; }
}

how to send this data xamarin to server..

~~

HttpClient Sending X509 Certificate

$
0
0

Hey Everyone,

I am working on a Xamarin Forms project that needs to send out a Http request that includes a certificate for authentication.

I have the code working to get the certificate, which is a PFX, and pass it to my HttpClient but when I make the request I always get back a 403 error. The code below is how I am sending the message:

// Attach certifcate collection to handler.
 var handler = new HttpClientHandler();
 handler.ClientCertificateOptions = ClientCertificateOption.Manual;
 handler.ClientCertificates.AddRange(GetCertificate());

 // Construct client with handler.
var client = new HttpClient(handler);

// Make request.
var result = client.GetAsync("urlgoeshere").GetAwaiter().GetResult();
var responsebody = result.Content.ReadAsStringAsync().GetAwaiter().GetResult();

I removed the real URL, but with the correct one it is always a 403 error.

I then tested this with a HttpWebRequest and I get through just fine, the code for that is as follows:

X509Certificate2Collection certificate = GetCertificate();
var httpRequest = (HttpWebRequest)WebRequest.Create("urlgoeshere");
httpRequest.ClientCertificates = certificate;
HttpWebResponse response = (HttpWebResponse)httpRequest.GetResponse();

So I am curious if anyone has seen this before and if they have what the difference is? And how you could get this fixed to work with the HttpClient?

Viewing all 79144 articles
Browse latest View live


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