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

Get Rg.Plugin.Popup button click event to another page

$
0
0

I have a content page and Its have a button. when click it its shows a popup.

CustomPopup = new CustomPopup(CustomMsg, MessageHeader, ButtonOne, ButtonTwo, ConfirmButton, MessageType);
await PopupNavigation.Instance.PushAsync(CustomPopup);

My Popup is in the PopupPage. If user click ok button in the popup I need to do some actions in the content page. Is there are way to get popup value to content page. please give some suggesions. I have found some answers but not worked


Problem with XAML x:Name and access from code-behind

$
0
0

Hi all.

I'm new to Xamarin Forms and have made a Xamarin Forms PCL project and added a few pages to it. So far the app is compiling and running fine on my samsung galaxy s5. :D But when a make a new Entry tag in the xaml file and give it a x:Name so that i can access it from code-behind, i can't, i need to restart Xamarin Studio to access it and se all the methods and properties is has. I have tried to search google for a similar problem, but with no luck.
So my question is, does someone know how to solve this problem? As far as i know, it has something to do with a g.cs file no being generated.

My system is a Macbook Air fully updated, and with Xamarin Studio 5.5, and i have a indie license for android.

Kind regards
Steffen

Remove TabbedPage Padding on UWP Xamarin Forms

$
0
0

Hello, when I build my Solution, the UWP version adds automaticaly a padding to the child page.
I tried a lot of things but I could take out that padding.

Thanks

Fast ping sweep?

$
0
0

I'm trying to develop an application in Xamarin.Forms which requires a ping sweep system, as to find the active addresses in a local network. I've tested an asynchronous approach on a c# console application, in Windows, and it runs pretty much instantly, at around 500 ms. That said, when I tried to use the same code in Xamarin.Forms, it takes more than 30 seconds to finish pinging. I'm sure its not my device, because I already tested it on an emulator and other android phones. What method should I use? I wish I could post the code I'm using, but I'm not allowed to post links yet.

How to use svg image for tabbed page tabbar icon?

$
0
0

I searched around and found that we can use third-party library to render svg in pages. But I don't know how to use svg as tabbar icon. Can anyone help me on it please?

MVVM - Performing an action in ViewModel from page OnAppearing

$
0
0

I've got a full MVVM implementation which is working nicely, for a project which communicates with BLE devices.

My problem is that I want to delay connecting to the device until the Page is appearing, and also disconnect when the user leaves the Page.

I assume I need to use the OnAppearing and OnDisappearing overrides for the Page.

However, how do I call methods in my ViewModel? Previous posts indicate I need to use MessagingCenter to message between the Page and the ViewModel. Is this still the best way?

How to change NavigationPage app icon size?

$
0
0

The app icon in my NavigationPage is huge

Even worse, when I navigate to another page, it leaves a huge margin for no discernible reason

Is there any way to fix this? I've read you can use TitleView to customize the header, but that doesn't seem to work.

There's no code to show other than MainPage = new NavigationPage(new MainPage()). I do have an icon.xml in mipmap-anydpi-v26/. When I remove that, the icon is still large but it also becomes square for some reason.

Invoking a new page on a logic condition, rather than on an event

$
0
0

How do I invoke a new page, on a certain logic condition? Xamarin tutorials appear to assume that navigation pages exclusively appear on simplified button-clicked events, from which the navigation is triggered — such as this.

        async void OnConfigButtonClicked(object sender, EventArgs e)
        {
            await Navigation.PushAsync(new ConfigPage
            {
                BindingContext = (Note)BindingContext
            }) ;
        }

What if I need to trigger "ConfigPage", based on my code logic when the application is proceeding with its start-up of the main page, rather than the user clicking a button?

I've tried to do below, but the error is "The 'await' operator can only be used within an async method" which I do partially understand, as it isn't wrapped within async, but how should I get around this? Thanks.

    public partial class NotesPage : ContentPage
    {
        public NotesPage()
        {
            InitializeComponent();

            var configFilename = "testfile.txt";
            if (!File.Exists(configFilename))
            {
                await Navigation.PushAsync(new ConfigPage
                {
                });
                File.WriteAllText(configFilename, App.deviceName);
            }
        }
    }


Persian Number

$
0
0

How to show all numbers in Persian
Is it a function that does this automatically?

google drive in xamarin forms

$
0
0

Can ayone help hot to integrate google drive in xamarin forms

Forms App restarts Every time when I bring it back from the background.

$
0
0

The App restarts from the root login page every time I bring it back from the Background, it doesn't continue. I tried with a lot of solutions that I found online. Nothing worked.
I tried to handle it from native mainactivity under OnCreate( )(refer the code below) :

            var myIntent = new Intent();
    if (!IsTaskRoot && myIntent.HasCategory(Intent.CategoryLauncher) 
                && myIntent.Action != null && myIntent.Action.Equals(Intent.ActionMain))
            {
                Finish();
                return;
            }

And also, I tried changing various options for activity launch mode from the Manifest . None of them worked. Few of the answers suggested that this may be due to Memory Management( Low Cost /Low Memory Devices ) but this is not the case with me.
After a lot of research I came to know that I have to Disable **"Don't Keep Activities" **option from the Developer Options Settings - this actually worked and I stopped facing the mentioned issue but I am not able to control this setting programmatically. Any help with this issue will be appreciated. Thanks

How to call an azure function in a secure way

$
0
0

We have a list of azure functions that we would like to call from the xamarin forms app.(user should not be prompted a login,all silent calls)

Functions have AuthorizationLevel=Function and therefore requires a function Key.

Where do you store the functionKey? definetely not in the app, I have read that the vault is not the way to do it.

How do you do it? is SAS the way to do it? or vault?
cannot find anything as guidance

any suggestions

SSL Connection could not be established to Azure Blob Storage

$
0
0

I have created as= Xamarin Project to upload images to Azure Blob Storage. While I am trying to access the Blob storage from my Local Machine. I am getting the following error while calling the below methods.

await container.CreateIfNotExistsAsync();

await blockBlob.UploadFromStreamAsync(stream);

SKGLView clears canvas between every Dispatcher.BeginInvokeOnMainThread

$
0
0

In a Xamarin Forms app i use a SKGLView to write spokes to a circle via the GPU, the thing is the whole canvas gets completly redrawn(cleared) with every call to
Dispatcher.BeginInvokeOnMainThread(() =>{SKGLView.InvalidateSurface(); }); not just update the spoke of 10 degrees.
But if i use a SKCanvasView instead with the same code the canvas keeps the rest of the circle and updates the spoke as expected.
The Dispatcher.BeginInvokeOnMainThread(() is called from an SignalR.On event.
All this is done on an Android emulator.
Thx Peder

Xamarin Forms iOS app is running perfectly on an emulator but crashing after splash screen on iPhone

$
0
0

Hi,

My Xamarin Forms iOS app is running perfectly on an emulator but crashing after splash screen on an iPhone device. I tried all the accepted from Xamarin Forums and StackOverflow. Nothing seems working.

I put try-catch blocks on Main.cs, AppDelegate.cs under the Xamarin Forms iOS app and under App.xaml.cs in the Xamarin Forms, it is not even triggering my try-catch blocks, even before the app crashes.

This occurs only on the real device [iPhone 6s iOS 13.3]


How can I fix this error : "java.exe exited with code 1 ", I'm using Visual Studio 2017

Full Screen Image Viewer (with Pinch to Zoom, Pan to Move, Tap to show captions) for Xamarin forms.

$
0
0

I'm working on a full screen image page that supports pinch to zoom, pan to move and tap to show captions. I'm basing this on how image viewer works in apps such as Facebook and Yelp. My code is built off Xamarin examples on gesture recognizers, which can be found at https://developer.xamarin.com/guides/xamarin-forms/user-interface/gestures/

My problem is that when the image is zoomed in and I rotate the device, and then zoomed out. The image is off the center. I would really appreciate it very much if someone can help me finish this, so it supports varying device orientations.

using System;
using System.ComponentModel;
using Xamarin.Forms;

namespace TurfDoctor
{
    public class FullScreenImagePage : ContentPage
    {
        double currentScale = 1;
        double startScale = 1;
        double xOffset = 0;
        double yOffset = 0;

        double originalWidth;
        double originalHeight;

        double ScreenWidth;
        double ScreenHeight;

        PanGestureRecognizer panGesture;

        bool showEverything = false;
        StackLayout imageDescription;
        Button backButton;
        BoxView topBox;
        Image image;
        ContentView imageContainer;
        Label indexLabel;
        //Label xLabel, yLabel, transXLabel, transYLabel, widthLabel, heightLabel, scaleLabel, screenWidthLabel, screenHeightLabel;
        AbsoluteLayout absoluteLayout;

        protected override void OnAppearing ()
        {
            ShowEverything = true;
            base.OnAppearing ();
        }

        protected override bool OnBackButtonPressed ()
        {
            App.NavPage.BarTextColor = Color.Black; // turn the status bar back to black
            return base.OnBackButtonPressed ();
        }

        public bool ShowEverything
        {
            set{
                    showEverything = value;
                    backButton.IsVisible = showEverything;
                    imageDescription.IsVisible = showEverything;
                    topBox.IsVisible = showEverything;
                    indexLabel.IsVisible = showEverything;

                    if (!showEverything) {
                        // hide the status bar by turning it black
                        App.NavPage.BarTextColor = Color.Black;
                        imageContainer.GestureRecognizers.Add (panGesture);
                    } else {
                        // show the status bar by turning it white
                        App.NavPage.BarTextColor = Color.White;
                        imageContainer.GestureRecognizers.Remove (panGesture);
                    }
            }
            get{
                return showEverything;
            }
        }

        public FullScreenImagePage (String ImageName, string DescriptionText, int index, int count)
        {
            NavigationPage.SetHasNavigationBar (this, false);

            image = new Image {
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions = LayoutOptions.CenterAndExpand,
                Aspect = Aspect.AspectFill, 
                Source = ImageName
            };

            imageContainer = new ContentView {
                Content = image
            };

            var tapGesture = new TapGestureRecognizer ();
            tapGesture.Tapped += OnTapped;
            imageContainer.GestureRecognizers.Add (tapGesture);

            var pinchGesture = new PinchGestureRecognizer ();
            pinchGesture.PinchUpdated += OnPinchUpdated;
            imageContainer.GestureRecognizers.Add (pinchGesture);

            panGesture = new PanGestureRecognizer ();
            panGesture.PanUpdated += OnPanUpdated;
            imageContainer.GestureRecognizers.Add (panGesture);

            absoluteLayout = new AbsoluteLayout {
                BackgroundColor = MyAppStyle.blackColor,
            };

            var label = new Label { 
                Text = DescriptionText, 
                TextColor = MyAppStyle.whiteColor, 
                FontAttributes = FontAttributes.Bold,
                FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label))
            };
            var separator = new BoxView() { HeightRequest = 1, BackgroundColor = MyAppStyle.whiteColor};

            imageDescription = new StackLayout {
                Padding = new Thickness(20),
                HorizontalOptions = LayoutOptions.Fill,
                Orientation = StackOrientation.Vertical,
                Children = { label, separator}
            };

            backButton = new Button { Text = "Back", WidthRequest = 80, HeightRequest = 40, TextColor = MyAppStyle.whiteColor, FontAttributes = FontAttributes.Bold };
            backButton.Clicked += (object sender, EventArgs e) => { OnBackButtonPressed(); Navigation.PopAsync(); };

            indexLabel = new Label {
                Text = (index + 1).ToString () + " of " + count.ToString (),
                TextColor = MyAppStyle.whiteColor,
                FontAttributes = FontAttributes.Bold,
                HorizontalTextAlignment = TextAlignment.Center
            };

            AbsoluteLayout.SetLayoutFlags (imageContainer, AbsoluteLayoutFlags.All);
            AbsoluteLayout.SetLayoutBounds (imageContainer, new Rectangle (0f, 0f, 1f, 1f));
            absoluteLayout.Children.Add (imageContainer);

            AbsoluteLayout.SetLayoutFlags (imageDescription, AbsoluteLayoutFlags.PositionProportional | AbsoluteLayoutFlags.WidthProportional);
            AbsoluteLayout.SetLayoutBounds (imageDescription, new Rectangle(0f, 1f, 1f, AbsoluteLayout.AutoSize));
            absoluteLayout.Children.Add(imageDescription);

            topBox = new BoxView { Color = MyAppStyle.blackColor, Opacity = 0.5 };
            AbsoluteLayout.SetLayoutFlags (topBox, AbsoluteLayoutFlags.WidthProportional);
            AbsoluteLayout.SetLayoutBounds (topBox, new Rectangle(0f, 0f, 1f, 50f));
            absoluteLayout.Children.Add (topBox);

            AbsoluteLayout.SetLayoutFlags (backButton, AbsoluteLayoutFlags.None);
            AbsoluteLayout.SetLayoutBounds (backButton, new Rectangle(0f, 10f, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));
            absoluteLayout.Children.Add (backButton);

            AbsoluteLayout.SetLayoutFlags (indexLabel, AbsoluteLayoutFlags.XProportional);
            AbsoluteLayout.SetLayoutBounds (indexLabel, new Rectangle(.5f, 20f, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));
            absoluteLayout.Children.Add (indexLabel);

            Content = absoluteLayout;
        }

        protected override void OnSizeAllocated(double width, double height)
        {
            base.OnSizeAllocated(width, height); //must be called

            if (ScreenWidth != width || ScreenHeight != height) {

                absoluteLayout.ForceLayout();

                originalWidth = imageContainer.Content.Width /  imageContainer.Content.Scale;
                originalHeight = imageContainer.Content.Height / imageContainer.Content.Scale;

                ScreenWidth = width;
                ScreenHeight = height;

                xOffset = imageContainer.Content.TranslationX;
                yOffset = imageContainer.Content.TranslationY;

                currentScale = imageContainer.Content.Scale;
            }
        }

        void OnTapped(object sender, EventArgs e)
        {
            ShowEverything = !ShowEverything;
        }

        void OnPanUpdated (object sender, PanUpdatedEventArgs e)
        {
            var s = (ContentView)sender;

            // do not allow pan if the image is in its intial size
            if (currentScale == 1)
                return;

            switch (e.StatusType) {
            case GestureStatus.Running:

                double xTrans = xOffset + e.TotalX, yTrans = yOffset + e.TotalY;
                // do not allow verical scorlling unless the image size is bigger than the screen
                s.Content.TranslateTo (xTrans, yTrans, 0, Easing.Linear);

                break;

            case GestureStatus.Completed:
                // Store the translation applied during the pan
                xOffset = s.Content.TranslationX;
                yOffset = s.Content.TranslationY;

                // center the image if the width of the image is smaller than the screen width
                if (originalWidth * currentScale < ScreenWidth && ScreenWidth > ScreenHeight)
                    xOffset = (ScreenWidth - originalWidth*currentScale)/2 - s.Content.X;
                else
                    xOffset = Math.Max (Math.Min (0, xOffset), -Math.Abs (originalWidth * currentScale - ScreenWidth));

                // center the image if the height of the image is smaller than the screen height
                if (originalHeight * currentScale < ScreenHeight && ScreenHeight > ScreenWidth)
                    yOffset = (ScreenHeight - originalHeight*currentScale)/2 - s.Content.Y;
                else
                    yOffset = Math.Max (Math.Min ((originalHeight - ScreenHeight)/2, yOffset), -Math.Abs(originalHeight*currentScale - ScreenHeight - (originalHeight - ScreenHeight)/2));

                // bounce the image back to inside the bounds
                s.Content.TranslateTo (xOffset, yOffset, 500, Easing.BounceOut);
                break;
            }
        }

        void OnPinchUpdated (object sender, PinchGestureUpdatedEventArgs e)
        {
            var s = (ContentView)sender;

            if (e.Status == GestureStatus.Started) {
                // Store the current scale factor applied to the wrapped user interface element,
                // and zero the components for the center point of the translate transform.
                startScale = s.Content.Scale;
                s.Content.AnchorX = 0;
                s.Content.AnchorY = 0;
            }
            if (e.Status == GestureStatus.Running) {

                // Calculate the scale factor to be applied.
                currentScale += (e.Scale - 1) * startScale;
                currentScale = Math.Max (1, currentScale);
                currentScale = Math.Min (currentScale, 5);

                //scaleLabel.Text = "Scale: " + currentScale.ToString ();

                if (currentScale == 1)
                    ShowEverything = true;
                else
                    ShowEverything = false;

                // The ScaleOrigin is in relative coordinates to the wrapped user interface element,
                // so get the X pixel coordinate.
                double renderedX = s.Content.X + xOffset;
                double deltaX = renderedX / ScreenWidth;
                double deltaWidth = ScreenWidth / (s.Content.Width * startScale);
                double originX = (e.ScaleOrigin.X - deltaX) * deltaWidth;

                // The ScaleOrigin is in relative coordinates to the wrapped user interface element,
                // so get the Y pixel coordinate.
                double renderedY = s.Content.Y + yOffset;
                double deltaY = renderedY / ScreenHeight;
                double deltaHeight = ScreenHeight / (s.Content.Height * startScale);
                double originY = (e.ScaleOrigin.Y - deltaY) * deltaHeight;

                // Calculate the transformed element pixel coordinates.
                double targetX = xOffset - (originX * s.Content.Width) * (currentScale - startScale);
                double targetY = yOffset - (originY * s.Content.Height) * (currentScale - startScale);

                // Apply translation based on the change in origin.
                var transX = targetX.Clamp (-s.Content.Width * (currentScale - 1), 0);
                var transY = targetY.Clamp (-s.Content.Height * (currentScale - 1), 0);
                s.Content.TranslateTo (transX, transY, 0, Easing.Linear);

                // Apply scale factor.
                s.Content.Scale = currentScale;
            }
            if (e.Status == GestureStatus.Completed) {
                // Store the translation applied during the pan
                xOffset = s.Content.TranslationX;
                yOffset = s.Content.TranslationY;

                // center the image if the width of the image is smaller than the screen width
                if (originalWidth * currentScale < ScreenWidth && ScreenWidth > ScreenHeight)
                    xOffset = (ScreenWidth - originalWidth*currentScale)/2 - s.Content.X;
                else
                    xOffset = Math.Max (Math.Min (0, xOffset), -Math.Abs (originalWidth * currentScale - ScreenWidth));

                // center the image if the height of the image is smaller than the screen height
                if (originalHeight * currentScale < ScreenHeight && ScreenHeight > ScreenWidth)
                    yOffset = (ScreenHeight - originalHeight*currentScale)/2 - s.Content.Y;
                else
                    yOffset = Math.Max (Math.Min ((originalHeight - ScreenHeight)/2, yOffset), -Math.Abs(originalHeight*currentScale - ScreenHeight - (originalHeight - ScreenHeight)/2));

                // bounce the image back to inside the bounds
                s.Content.TranslateTo (xOffset, yOffset, 500, Easing.BounceOut);
            }
        }
    }
}

ListView TextColor

$
0
0

In my Xamarin Forms app, I'm trying to change the text color of my listview items. In the UWP the items are black, which I want but in the Android Listview they are silver.

I've tried to add a simple Listview.ItemTemplate but not successful.

Here is my xaml

     <StackLayout Grid.Row="2"  Grid.RowSpan="2" Grid.Column="1" Grid.ColumnSpan="2" Orientation="Vertical" HorizontalOptions="FillAndExpand">
                            <ListView x:Name="SelectionListBox" Grid.Column="0" Grid.ColumnSpan="3" >

                            </ListView>
                        </StackLayout>

And here is the .cs code.

  List<Templates> templates = App.Database.GetAllTemplates();
                    myCollection = templates.Select(x => $"{x.TemplateFile.ToString()} ~ {x.TemplateName} ~ {x.Category}").ToList();

 SelectionListBox.ItemsSource = myCollection;

Shell tab main

$
0
0

Hello,

I have 5 tabs in my app and a login page, logic should be started when tabs are loaded, is there any way to do MainViewModel? Right now I do that logic in the first tab (Tab1ViewModel), but I don't want to do it there. In AppShell constructor it can't work, because login may come first

   <!-- Login -->
   <ShellItem Route="login">
         <ShellContent ContentTemplate="{DataTemplate Pages:LoginPage}" />
  </ShellItem>

    <!-- Main -->
        <TabBar Route="main">
        <Tab>
        <Tab>
        <Tab>
        <Tab>
        <Tab>
        </TabBar>

AppShell:

                public AppShell()
                        {
                            InitializeComponent();

                            RegisterRoutes();

                            bool mainLogin = Preferences.ContainsKey("rememberLogin");

                            if (mainLogin)
                            {
                                GoToAsync("//main");
                            }
                        }

Null reference exception in production at Xamarin.Forms.NavigationPage.GetHasBackButton

$
0
0

I am facing null reference exception in production at but not able to reproduce in dev. I am not getting any idea where is this coming from. Have anybody faced this?

The whole stack trace is below:

[Message:Value cannot be null.
Parameter name: page]==[StackTrace: at Xamarin.Forms.NavigationPage.GetHasBackButton (Xamarin.Forms.Page page) <0xa9c554 + 0x000a0> in :0
at Xamarin.Forms.Platform.iOS.NavigationRenderer.UpdateLeftBarButtonItem (Xamarin.Forms.Platform.iOS.ParentingViewController containerController) <0xbef714 + 0x0009f> in :0
at Xamarin.Forms.Platform.iOS.NavigationRenderer.<.ctor>b__9_0 (IVisualElementRenderer sender) <0xbf0184 + 0x000af> in :0
at Xamarin.Forms.MessagingCenter+<>c__DisplayClass4_0`1[TSender].b__0 (System.Object sender, System.Object args) <0xab1734 + 0x0009f> in :0
at Xamarin.Forms.MessagingCenter.InnerSend (System.String message, System.Type senderType, System.Type argType, System.Object sender, System.Object args) <0xab0f44 + 0x001b7> in :0
at Xamarin.Forms.MessagingCenter.Send[TSender] (Xamarin.Forms.TSender sender, System.String message) <0xab0a60 + 0x0004f> in :0
at Xamarin.Forms.Platform.iOS.TabletMasterDetailRenderer.HandlePropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e) <0xc00b30 + 0x0016f> in :0
at (wrapper delegate-invoke) :invoke_void_object_PropertyChangedEventArgs (object,System.ComponentModel.PropertyChangedEventArgs)
at Xamarin.Forms.BindableObject.OnPropertyChanged (System.String propertyName) <0xa73c50 + 0x0006b> in :0
at Xamarin.Forms.Element.OnPropertyChanged (System.String propertyName) <0xafaf04 + 0x0002f> in :0
at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindablePropertyContext context, System.Object value, Boolean currentlyApplying, SetValueFlags attributes, Boolean silent) <0xa754e8 + 0x00273> in :0
at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes) <0xa74818 + 0x00357> in :0
at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, Boolean fromStyle, Boolean checkAccess) <0xa7531c + 0x0011b> in :0
at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value) <0xa73a1c + 0x0003b> in :0
at Xamarin.Forms.MasterDetailPage.set_IsPresented (Boolean value) <0xad4bcc + 0x0005b> in :0
at Xamarin.Forms.Platform.iOS.NavigationRenderer.b__58_0 (System.Object o, System.EventArgs e) <0xbf0460 + 0x00057> in :0
at UIKit.UIBarButtonItem+Callback.Call (Foundation.NSObject sender) <0x1b4c54 + 0x0005f> in :0
at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) <0x1b2108 + 0x00033> in :0
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) <0x1b2030 + 0x000cb> in :0

Viewing all 79144 articles
Browse latest View live


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