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

Extract MMPK File from an Android Device

$
0
0

Hey,

im trying to create an App that can load a MMPK File. (From an Esri Tutorial, cant post a Link at the moment)
I put the MMPK File in to my Device and tried to open it with:

var filePath = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath;
var mapPackagePath = Path.Combine(filePath, "Test.mmpk");

When i Deploy, the App is tring to read the File. But it send me an Error:
Esri.ArcGISRuntime.ArcGISRuntimeException: 'Invalid access: Mobile map package failed to open. Check the archive format is correct, zip file with no compression.'
Do u guys know how i can extract this File, from my Device?

Thanks for helping


Automatic Provisioning failed, please check the logs

$
0
0

Hello,

I am trying to test cross platform app on iOS physical device from visual studio 2019 (16.6.1) by pairing to Mac. I have paid apple developer account.
Steps I followed.
1. Created app
2. successfully paired with Mac
3. Successfully signed in apple account
4. I had followed all these steps.

But I am keep on getting "Automatic Provisioning failed, please check the logs" after repetitive retry.. Moreover I am not able to find where to see logs for error as none of the output window (build, build order, xamarin, xamarin diagnostics) shows mentioning of automatic provisioning failed. Where can I see logs to identify exact problem, if at all logs are creating.

Xamarin Forms: How to run a service every x seconds even the app is in background?

$
0
0

I am using the following code for calling a function every 10 seconds.

var startTimeSpan = TimeSpan.Zero;
var periodTimeSpan = TimeSpan.FromSeconds(10);

var timer = new System.Threading.Timer((e) =>
{
    MyFunction();
}, null, startTimeSpan, periodTimeSpan);

MyFunction() will execute every 10 seconds when the app is on the open state. When the app is in the background, that function is not invoking.

So how can I invoke a function when the app is in the background? Are there any NuGet packages for this or we need to do this using the dependency service?

How to Hide/Show Searchbar & Toolbar while scrolling the listview in Xamarin forms PCL?

$
0
0

I have a list view, i need to hide toolbar/Navigation bar while scrolling. I have followed this tutorial for Search bar. It is working while appearing disappearing screen is flickering. I need to show/hide like whatsapp. I have attached one sample image. Please help me to achieve this in Xamarin forms PCL.

Pass Variable from Rg.popup to contentpage

$
0
0

Hi,
In my content page I Have this call that show my popup

await PopupNavigation.Instance.PushAsync(new AlertHandler("Pairing", "Device is not paired. Do you want to pair it?", "No", "Yes"));

and the code of PopUpPage is:

    public partial class AlertHandler : Rg.Plugins.Popup.Pages.PopupPage
    {
            bool chose;
            public AlertHandler(string Title, string Body, string Button1, string Button2)
            {
                InitializeComponent();
                aTitle.Text = Title;
                aBody.Text = Body;
                afButton.Text = Button1;
                asButton.Text = Button2;
            }
    }

I would like to know how I can pass a boolean from popuppage to contentpage.
I have already tried MessagingCenter but doesn't work.

Thankyou in advance.
David.

Random slow downs when transitioning

$
0
0

Hello Community

I am doing an app, that connects to a server, to register users, and login users, wen the user is logged in, I transition into a master page, where I have three button and my hamburger Icons (those work fine) except the logout, I sometimes get delay.

I am Using the MVVM pattern all the time and x:bindings

Here are my view Models.

LoginVM

 private string result;

        public ICommand LoginCommand { get; set; }
        public ICommand GoToRegisterCommand { get; set; }
        public HttpResponseMessage Msg { get; set; }
        public JObject Obj { get; set; }
        public LoginViewModel() {

            IsVisible = true;
            IsBusy = false;
            IsEnable = false;

            LoginCommand = new Command(async () => {
                IsVisible = false;
                IsBusy = true;

                await Task.Run(async () => {
                    Obj = new JObject {
                { "username", Username.ToLower() },
                { "password", Password.ToLower() }
                    };

                    Msg = await NetworkHelpper.SendData(Constants.AUTH, Obj);

                    if (Msg == null)
                        return;

                    MainThread.BeginInvokeOnMainThread(async () => {


                        if (Msg.IsSuccessStatusCode) {
                            result = Msg.Content.ReadAsStringAsync().Result;
                            var details = JObject.Parse(result);
                            string token = details["token"].ToString();
                            await SecureStorage.SetAsync(Constants.TOKEN_KEY, token);
                            IsBusy = false;
                            await Application.Current.MainPage.Navigation.PushAsync(new HomeMaster());
                        } else {
                            IsVisible = true;
                            IsBusy = false;
                            result = Msg.Content.ReadAsStringAsync().Result;
                            await Application.Current.MainPage.DisplayAlert("Error", result, "ok");
                        }
                    });

                });
            });
            GoToRegisterCommand = new Command(async () => {
                await Application.Current.MainPage.Navigation.PushAsync(new RegisterScreen());
            });
        }

RegisterVM

   public ICommand RegisterCommand { get; set; }
        public ICommand FacebookCommand { get; set; }
        public ICommand GmailCommand { get; set; }
        public JObject Object { get; set; }
        public HttpResponseMessage Msg { get; set; }
        public RegisterViewModel() {

            IsVisible = true;
            IsEnable = false;
            IsBusy = false;
            FacebookCommand = new Command(async () => {
                await Application.Current.MainPage.DisplayAlert("", "Calling facebook", "OK");
            });
            GmailCommand = new Command(async () => {
                await Application.Current.MainPage.DisplayAlert("", "Calling Gmail", "OK");
            });
            RegisterCommand = new Command(async () => {
                IsBusy = true;
                IsVisible = false;
                await Task.Run(async () => {
                    Object = new JObject {
                { "username", Username.ToLower() },
                { "password", Password.ToLower() },
                { "email", Email.ToLower()}
                    };

                    Msg = await NetworkHelpper.SendData(Constants.REGISTER, Object);

                    MainThread.BeginInvokeOnMainThread(async () => {
                        if (Msg == null)
                            return;

                        if (Msg.IsSuccessStatusCode) {
                            IsBusy = false;
                            IsVisible = true;
                            await Application.Current.MainPage.Navigation.PushAsync(new LoginScreen());
                        } else {
                            IsBusy = false;
                            IsVisible = true;
                            result = Msg.Content.ReadAsStringAsync().Result;
                            await Application.Current.MainPage.DisplayAlert("Error", result, "ok");
                        }
                    });

                });
            });
        }

HomeVM

 class HomeViewModel : BaseViewModel {
        public ICommand GoToProfile { get; set; }
        public HomeViewModel() {

            GoToProfile = new Command(async () => {
                Page app = Application.Current.MainPage;
                await app.Navigation.PushAsync(new ProfileScreen(), true);
            });

        }

This is my view for the home

    <NavigationPage.TitleView>
        <StackLayout Spacing="30"
                     Orientation="Horizontal"
                     VerticalOptions="Center"
                     HorizontalOptions="Center">
            <Image Source="LogoTexto.png"
                   WidthRequest="200" />
            <Image Source="CampanaNotificaciones.png" />
        </StackLayout>
    </NavigationPage.TitleView>

    <ContentPage.Content>
        <ScrollView>
             <StackLayout Padding="20"
                     HorizontalOptions="Center">
                <Frame CornerRadius="100"
                       WidthRequest="58"
                       HeightRequest="58"
                       VerticalOptions="Center"
                       HorizontalOptions="Center">
                    <Image Source="mm.png"
                           VerticalOptions="Center"
                           HorizontalOptions="Center" />
                </Frame>
                <Label Text="Megaman" />
                <StackLayout Orientation="Vertical"
                         Spacing="5">

                <StackLayout Orientation="Horizontal"
                             HorizontalOptions="Center"
                             Margin="0,0,40,0">
                    <Button Text="Mis mascotas"
                            ContentLayout="Left,20"
                            Image="Mis_mascotas.png"
                            HorizontalOptions="Start"
                            BackgroundColor="Transparent" />

                </StackLayout>
                <StackLayout Orientation="Horizontal"
                             HorizontalOptions="Center">
                    <Button Text="Agenda de control"
                            ContentLayout="Left,20"
                            Image="Agenda_control.png"
                            HorizontalOptions="Start"
                            BackgroundColor="Transparent" />

                </StackLayout>
                <StackLayout Orientation="Horizontal"
                             HorizontalOptions="Center">
                    <Button Text="Pareja encontrada"
                            ContentLayout="Left,20"
                            Image="Pareja_encontrada.png"
                            HorizontalOptions="Start"
                            BackgroundColor="Transparent" />

                </StackLayout>
                <StackLayout Orientation="Horizontal"
                             HorizontalOptions="Center"
                             Margin="0,0,30,0">
                    <Button Text="Editar mi perfil"
                            Command="{x:Binding GoToProfile}"
                            ContentLayout="Left,20"
                            Image="Editar.png"
                            HorizontalOptions="Start"
                            BackgroundColor="Transparent" />
                </StackLayout>
            </StackLayout>
            <StackLayout Margin="0,40,0,0"
                         Spacing="20">
                <Image Source="BotonCompra.png" />
                <Button BackgroundColor="{x:StaticResource ThirdColor}"
                        Text="¿Quieres poner a tu mascota en adopción?"
                        CornerRadius="20"
                        TextColor="{x:StaticResource BtonsColor}" />
                <Button BackgroundColor="{x:StaticResource ThirdColor}"
                        Text="¿Quieres poner a tu mascota disponible en busqueda de parejas?"
                        CornerRadius="20"
                        TextColor="{x:StaticResource BtonsColor}" />
            </StackLayout>
        </StackLayout>
        </ScrollView>

    </ContentPage.Content>

The master for the home

  <MasterDetailPage.Master>
        <menu:HamburgerMenu />
    </MasterDetailPage.Master>

    <MasterDetailPage.Detail>
        <NavigationPage>
            <x:Arguments>
                <View:HomeScreen />
            </x:Arguments>
        </NavigationPage>
    </MasterDetailPage.Detail>
</MasterDetailPage>

The botton that is on the home, that is bound to my VM transition perfectly, but with a delay of 2 seconds, and also when I comeback and use the hamburger menu, when I come back it will flick white like for 1 millisecond (is anoyin lol)

When I see my console output, I can see the message "This app may be doing to much work on in its main thread"

Using Cybersource with Xamarin forms

$
0
0

Haven't anyone in this world tried to build a Xamarin forms application that uses the Cybersource online payment gateway??
I searched a lot but didn't find any sample, also I tried to build one from the C# sample provided by Cybersource.
But whenever I click on a Next button in the Webview I'm getting Session Timeout page.
Even though I'm setting the cookie in the Webview in the following way:

        CookieContainer cookies = new CookieContainer();
        var domain = new Uri(webSource.BaseUrl).Host;
        var cookie = new Cookie
        {
            Secure = true,
            Expired = false,
            HttpOnly = false,
            Name = "cookie",
            Expires = DateTime.Now.AddDays(10),
            Domain = domain,
            Path = "/"
        };
        cookies.Add(cookie);
        paymentWebView.Cookies = cookies;

Anyone can help or have a clue about what's happening?

How can I remove the underline in SearBar on Android?

$
0
0

Hi devs,

Im using a SearchBar element and on iOS its working fine but on Android I see a underline. How can I remove this underline?
Can somebody help me?


Xamarin forms: How to parse HTML Data having video links?

$
0
0

I have video links(Vimeo video) and normal texts in my HTML data. I am using Xam.Plugin.HtmlLabel for parsing the HTML data. But it is not effective, the links are not clickable on the iPhone. Also, the video links are missing when coming to UI.

I have added my sample HTML data here. I am using a webview for showing videos. So the video links should open on the app itself using webview or any other property. And show the remaining description as normal text. I need a UI like this. How can I do this? My current UI using Xam.Plugin.HtmlLabel.

Xamarin Forms: Custom webview is not working in IOS

$
0
0

I am using Custom Webview for solving ITMS-90809: Deprecated API Usage - Apple will stop accepting submissions of apps that use UIWebView APIs. and parsing HTML data.

My Code:

MyWebView.cs

using Xamarin.Forms;

namespace CustomWebview
{
    public class MyWebView : WebView
    {
        public static readonly BindableProperty UrlProperty = BindableProperty.Create(
        propertyName: "Url",
        returnType: typeof(string),
        declaringType: typeof(MyWebView),
        defaultValue: default(string));

        public string Url
        {
            get { return (string)GetValue(UrlProperty); }
            set { SetValue(UrlProperty, value); }
        }
    }
}

IOS

using CustomWebview;
using CustomWebview.iOS;
using WebKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;

[assembly: ExportRenderer(typeof(MyWebView), typeof(MyWebViewRenderer))]

namespace CustomWebview.iOS
{
    public class MyWebViewRenderer : ViewRenderer<MyWebView, WKWebView>
    {
        WKWebView _wkWebView;

        protected override void OnElementChanged(ElementChangedEventArgs<MyWebView> e)
        {
            base.OnElementChanged(e);

            if (Control == null)
            {
                var config = new WKWebViewConfiguration();
                _wkWebView = new WKWebView(Frame, config);
                SetNativeControl(_wkWebView);
            }
            if (e.NewElement != null)
            {
                Control.LoadHtmlString(Element.Url, null);   //use this code instead
                //Control.LoadRequest(new NSUrlRequest(new NSUrl(Element.Url)));
            }
        }
    }
}

When I open the page having MyWebView the page redirects to Main.cs and shows the below exception.

enter image description here

I have uploaded a sample project here.

Setting Cookies in a WebView

$
0
0

I received a request this morning to share how I set cookies in a webview so here it is, hope it's helpful. It's worked for me so far but feel free to comment on it if it can be improved.
First, you have to create a custom render for your webview in iOS and Android, there are many examples of how to do that so I won't go into that here.
In my shared code I have a UserInfo object that contains a CookieContainer:

    public class UserInfo
    {
        public static CookieContainer CookieContainer = new CookieContainer();
    }

In my (native) login page I have an event called OnLoginClickAsync which validates the login information. I create a HTTPClientHandler:

                var handler =  new HttpClientHandler {CookieContainer = UserInfo.CookieContainer};
                var httpClient = new HttpClient(handler);

Then save the resulting CookieContainer if the validation is successful:

                UserInfo.CookieContainer = handler.CookieContainer;

On the Android side in the OnElementChanged event for my web view renderer I use:

            var cookieManager = CookieManager.Instance;
            cookieManager.SetAcceptCookie(true);
            cookieManager.RemoveAllCookie();
            var cookies = UserInfo.CookieContainer.GetCookies(new System.Uri(AppInfo.URL_BASE));
            for (var i = 0; i < cookies.Count; i++)
            {
                string cookieValue = cookies[i].Value;
                string cookieDomain = cookies[i].Domain;
                string cookieName = cookies[i].Name;
                cookieManager.SetCookie(cookieDomain, cookieName + "=" + cookieValue);
            }

On the iOS side in the OnElementChanged event for my web view renderer I use:

            // Set cookies here
            var cookieUrl = new Uri(AppInfo.URL_BASE);
            var cookieJar = NSHttpCookieStorage.SharedStorage;
            cookieJar.AcceptPolicy = NSHttpCookieAcceptPolicy.Always;
            foreach (var aCookie in cookieJar.Cookies)
            {
                cookieJar.DeleteCookie(aCookie);
            }

            var jCookies = UserInfo.CookieContainer.GetCookies(cookieUrl);
            IList<NSHttpCookie> eCookies = 
                (from object jCookie in jCookies 
                 where jCookie != null 
                 select (Cookie) jCookie 
                 into netCookie select new NSHttpCookie(netCookie)).ToList();
            cookieJar.SetCookies(eCookies.ToArray(), cookieUrl, cookieUrl);

Also, if you want to use the cookie container in a straight call - not in a webview - just set it in the handler:

            var handler = new HttpClientHandler { CookieContainer = cookieContainer };
            var httpClient = new HttpClient(handler);

Problem setting MasterDetailPage items. Can't be able to follow the Microsoft Docs tutorial HELP!!!

$
0
0

Hi guys I'm trying to follow the Microsoft docs "Xamarin.Forms Master-Detail Page" tutorial (the one who says 8 minutes read). I wanted to post the link but this thing is not letting me because of i'm a newbie. I want to display all the master menu items like in the native MasterDetailApps with the hamburger menu. But when trying to implement the "Creating the Master Page" part I'm getting stuck because an error:

the first error to pop up was the blue one, the metadata .dll erros pop up after restarting visual studio. Please help, I don't know why the invalid attribute character is present, and also the metadata .dll errors are popping up after a while in every god damn vs solution that I made with Xamarin.Forms

Multiple monitor support for Xamarin.Forms UWP?

$
0
0

I am developing a UWP app where I want to open windows on each of the two screens that are connected to the computer. Is that possible with Xamarin.Forms for UWP?

Entry is not Clearing with Bindable Property

$
0
0

My 2 Entries is binded from a bindable property and working well but after saving the data from Entries i want to clear Entries value but this could not able to effect on my UI ,if i i use ctrl+ save on my xaml file the onproperty changed event fired and Entries clears. Also i have used a class in my bindable property with two get set variables. if i create seprate two diffrent bindable properties for two entries than it works but in a class it does not works .but i want use only single bindable property with class. I am sharing my code.

//Inotify class

 public  class   BaseViewModel : INotifyPropertyChanged
   {
   protected virtual void OnPropertyChanged(string propertyName)
       {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
        else
        {
            return;
        }
         }
      }

// model class

 public class NoModel
   {
    public string No { get; set; }
    public string Amt { get; set; }
  }

//on property change event

 public NoModel bindNoModel= new NoModel ();

 public NoModel BindNoModel
       {
        get { return bindNoModel; }
        set
        {
            bindNoModel= value;
            OnPropertyChanged(nameof(BindNoModel));
        }
       }

//my xaml code




        <StackLayout Orientation="Horizontal" HorizontalOptions="FillAndExpand" VerticalOptions="StartAndExpand">
            <Label WidthRequest="110" Text="Amount" VerticalOptions="Center" Font="Bold" FontSize="Medium" ></Label>
            <Entry Text="{Binding BindNoModel.Amt }" Placeholder="Enter Amount" ReturnType="Done"  ReturnCommand="{Binding SubmitCommand}" Keyboard="Numeric" HorizontalOptions="FillAndExpand" />
        </StackLayout>

//on save command

BindNoModel.No = string.Empty;
BindNoModel.Amt = string.Empty;

Note1 : Above code on save command does not work unitl i use ctrl +save on my xaml file and then UI changes.

Note 2 : This below code work if i create diffent properties

     public string no;
    public string No
    {
        get { return no; }
        set
        {
            no = value;
            OnPropertyChanged(nameof(No));
        }
    }

 public string amt ;
    public string Amt 
    {
        get { return amt ; }
        set
        {
            amt = value;
            OnPropertyChanged(nameof(Amt ));
        }
    }

//on save command

No = string.Empty;
Amt = string.Empty;

Load Content In Same Xaml Page With Different CollectionView

$
0
0

Hi Everyone,

I am working on a app that has load in same xamarin forms pages. my first CollectionView consists of items in a data template what I need help with is when the user clicks a item in the data template collection view it loads them to a different CollectionView in the same page. How to do that? Here's my code :


<CollectionView.ItemsLayout>

</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>







Xamarin Forms: Update to IOS13 introducing black screens

$
0
0

Hello Everyone,
I hope everyone is safe and sound.

We have Xamarin Forms app, where we support IOS version of the app. Everything was fine till Xamarin IOS 12.0. But Recently we tried to update to IOS 13.0 but we are seeing below black screen under menues. Not only that , some of our screen turned complete black. Not sure why this is happening. See images below:


Now, I have done some research for solution as example,
https://forums.xamarin.com/discussion/173358/black-screen-on-ios-13-help , this solution talking about a injection of properties in Info.plist

Though most of the suggetions regarding this issue on internet written in objective c or swift, I am trying to decode those.

By the mean time, just trying my luck here , if anyone in Xamarin world faced and resolved this issue.

Appreciate it.

Below My Environment Details:
VS 2019- version 8.6.5
Xamarin IOS- 13.18.2.1
Xcode-11.5
IOS SDK-13.5

How to Change pin's icon xamarin.forms

$
0
0

Hi guys,
I create a map with multiple Pins and i want to change the pin's icon.
Like this :

How to do it ? :/
Thx for looking

Change the slider Position on audio player

$
0
0
public int Position => Convert.ToInt32(players.Position.TotalSeconds);
 CrossMediaManager.Current.PositionChanged += (sender, e) =>
            {
                slider.Maximum = e.Position.TotalSeconds;
                slider.Value = e.Position.TotalSeconds;
            };
private void Slider_ValueChanged(object sender, ValueChangedEventArgs e)
        {
            slider.Value = CrossMediaManager.Current.Position.Seconds;

            //if (slider.Value != CrossMediaManager.Current.Duration.TotalSeconds)
            //{
            //    CrossMediaManager.Current.SeekTo(TimeSpan.FromSeconds(slider.Value));
            //}

        }
private bool UpdatePosition()
        {

            //slider.ValueChanged -= Slider_ValueChanged;
            slider.Value = CrossMediaManager.Current.Position.TotalSeconds;
            //slider.ValueChanged += Slider_ValueChanged;
            return CrossMediaManager.Current.IsPlaying();
        }

How to change dialog Colors of DatePickerDialog/TimePickerDialog when Material Visual is enabled?

$
0
0

Hi,

i was playing around with David Ortinaus "TheLittleThingsPlayground" to try out the Material Visuals.
What I noticed is, that the DatePickerDialog does not use the colorAccent defined in the styles.xml

<style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
        <item name="colorAccent">#FF4081</item>
</style>

but just uses black as header color.

When i remove the Visual="Material" property from the ContentPage Tag, the picker that gets opend uses the defined Color.

So how to change the Accent Color for the DatePickerDialog (and TimePicker as well) when the Material Visual is enabled?

Thanks & Cheers

Kai

Is TapGestureRecognizer obsolete?

$
0
0

Hello, after updating to the latest version of Xamarin the TapGestureRecognizer all of a sudden stopped working.

Is there something wrong that I need to update with my code? https://pastebin.com/iT9GVDxi

Viewing all 79144 articles
Browse latest View live


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