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

Buttons inside Listview

$
0
0

Hello everyone,

i implemented a Listview with two Buttons:

In Android everything works just fine, but on iOS the Listview "freezes" after i click the button. It is like the Listview looses focus or something. I just cannot scroll it after clicking one of the Buttons.

Does anyone had a similar problem in the past?

Thanks in advance!


How to detect text and search a location over mapview?

$
0
0

I added mapview using xamarin.forms.maps package. I wanted to add a searchbar field to search address and drop pin using search box.

How to add a SearchBar programmatically a search a location?

I tried the following:

var searchField = new SearchBar
{
Placeholder = "Enter search term"
};
searchField.SearchCommand = new Command(() => { if (searchField != null) { string.Format("Result: {0} is what you asked for.", searchField.Text); }
** // I don't get the text here**

Content = new StackLayout
{
Spacing = 0,
Children = {
searchField,
map,
buttons
}
};

Keeping Image paths in Resource file

$
0
0

I know it's good practice to use resource files to store strings and colors being used in views, but I can't figure out how to do the same with Images. I've tried using resource file both for images and strings (storing the file path), and neither works. I had the same problem with colors, and I ended up using a ResourceDictionary to keep them there, not sure the correct ways to put images in there if it's even possible.

Setting tint color of an Image

$
0
0

Is there a way to change the tint color of a Forms.Image programmatically? Both in Android and iOS. The source of the Image is a simple .png file with transparent layer.

I will welcome any other suggestions too.

Thanks in advance.

StaticResource OnPlatform for FontFamily

$
0
0

So my app uses the Hero custom font. I can declare it just fine this way:

<Style ApplyToDerivedTypes="True" TargetType="Label">
                <Setter Property="TextColor" Value="{StaticResource TextWhite}"/>
                <Setter Property="FontFamily">
                    <Setter.Value>
                        <OnPlatform x:TypeArguments="x:String">
                            <On Platform="iOS" Value="Hero"/>
                            <On Platform="Android" Value="Hero.otf#Hero"/>
                        </OnPlatform>
                    </Setter.Value>
                </Setter>
            </Style>

However, to be able to use it on different spots throughout the app (such as an Autocomplete field from Syncfusion, which has like 3 different FontFamily properties), I wanted to create a separate StaticResource just for the OnPlatform, like this:

        <OnPlatform x:Key="OnPlatformHeroFont" x:TypeArguments="x:String">
                <On Platform="iOS" Value="Hero"/>
                <On Platform="Android" Value="Hero.otf#Hero"/>
            </OnPlatform>

And then use a reference to it (Value="{StaticResource OnPlatformHeroFont}") both in the Syncfusion field and in the other Styles in the App.xaml file:

<Style ApplyToDerivedTypes="True" TargetType="Label">
                <Setter Property="TextColor" Value="{StaticResource TextWhite}"/>
                <Setter Property="FontFamily" Value="{StaticResource OnPlatformHeroFont}"/>
</Style>

However, this gives me a "Java.Lang.RuntimeException: Font asset not found Hero.otf#Hero" exception, while that first example (declared inside a style's setter tag) doesn't. Any ideas?

And yes, the font is inside of the Assets folder. As I said, it works fine in that first example.
Also, works fine on iOS.

Xamarin.uitest backdoor method to take picture

$
0
0

Our app uses the native device camera does anyone have a backdoor method to access and take picture?

So I have been scouring the internet for the past couple of days and have yet to find a resolution. I have "ideas" on what I need to do but am stumped. Our app relies heavily on taking pictures. I understand that the UITest isn't able to interact with the native camera, but has anyone created a backdoor method that will allow the user to either upload a photo as a mock and then interact with the app? Or if there is another solution I am open to hear. This is for xamarin.uitest

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);
            }
        }
    }
}

Printing rows of a xamarin.forms.listview in a UWP

$
0
0

Hi there,

Does anyone know how or know where I could look to find out how to print the rows of a xamarin listview in UWP? I've seen online examples of printing webviews, pdfs, images, etc., but I'm not sure how to print a listview. I'm using dependency injection and I'm just passing a parameter to my UWP implementation with the listview object.
Thanks


Possible to disable caching in WebView?

$
0
0
I need to be able to disable caching from the WebView, is that possible to do in Forms or even with a custom renderer?

WebView HtmlWebViewSource crashing the app

$
0
0

Hello,

I want to display html text using webview. Currently I am testing it on UWP. Problem is whenever I use WebView in my current XAML code it's crashes the app and throw exception on the last page. I even tried using some hard quote value but even that's not working.

My XAML Code:

<ContentPage.Content>

        <Image x:Name="ProductDetailsImage" WidthRequest="200" HeightRequest="200"></Image>
        <Label x:Name="ProductDetailsName" ></Label>
        <Label x:Name="ProductDetailsStartingFrom" ></Label>
        <Label x:Name="ProductDetailsBrand" ></Label>
        <Label x:Name="ProductDetailsSKU" ></Label>
        <Label x:Name="ProductDetailsMPN" ></Label>
        <Label x:Name="ProductDetailsStockStatus" ></Label>
        <Label x:Name="ProductDiscontinued" Text="Non-Returnable" IsVisible="False" ></Label>

        <Picker x:Name="SelectColorPicker" ItemDisplayBinding="{Binding name_str}" 
                SelectedItem="{Binding option_value_id}" IsVisible="False" Title="Select Color:"
                SelectedIndexChanged="SelectColorPicker_SelectedIndexChanged"></Picker>

        <Picker x:Name="SelectSizePicker" ItemDisplayBinding="{Binding name_str}"
                SelectedItem="{Binding option_value_id}" IsVisible="False" Title="Select Size:" 
                SelectedIndexChanged="SelectSizePicker_SelectedIndexChanged"></Picker>

        <Label Text="Enter Quantity: " x:Name="LabelQty" IsVisible="False"></Label>
        <Entry x:Name="ProductQty" Text="1" IsVisible="False"></Entry>
        <Button x:Name="AddToCart" Text="Add to Cart" IsVisible="False" Clicked="AddToCart_Clicked"></Button>
        <Button x:Name="AddToWishlist" Text="Add to Wishlist" IsVisible="False" Clicked="AddToWishlist_Clicked"></Button>     


        <WebView HeightRequest="100" WidthRequest="100">
            <WebView.Source>
                <HtmlWebViewSource x:Name="ProductHtmlWebViewSource"></HtmlWebViewSource>
            </WebView.Source>
        </WebView>

    </StackLayout>
</ContentPage.Content>

Code Behind:

ProductHtmlWebViewSource.Html = product.data.descriptions;

Any help would be appreciated.

Thank you

Could someone help me how to create a ipa file from visual studio 2017 MAC

$
0
0

I am new to xamarin forms and need some guidance creating an inhouse app IPA file to host on our company portal

Firebase Cloud Messaging (FCM) for Xamarin Forms ???

$
0
0

Recently google has introduced the updated or new version of GCM (Google Cloud Messaging) as FCM (Firebase Cloud Messaging), so my Question is do we have any component or sample to use it in xamarin Forms ????/

BottomNavigationView option for TabbedPage on Android

ScrollView doesn't scroll

$
0
0

I have a page with a scrollview wrapping a StackLayout - something I do on lots of pages and works great. However, on one page it does not - no scrolling, and when I click on the Editor control in the page the keyboard hides the Editor instead of scrolling.

There are two things I'm doing differently on this page - I have Image controls with no ImageSource (they are set by user interaction) and I have a section of the StackLayout that is hidden depending on the value of a switch. I've tried removing both of these to fix the problem, but it persists.

I recall seeing similar issues relating to this and the ScrollView not being able to figure out the sizing, but I can't find anything that points to the right solution.

What am I missing?

    <ContentPage.Content>
        <ScrollView>
            <StackLayout Padding="10" BackgroundColor="#cae5ee">
                <StackLayout Orientation="Horizontal">
                    <Label HorizontalOptions="FillAndExpand" VerticalOptions="Center" Text="Attended?" />
                    <Switch x:Name="Attended" />
                </StackLayout>

                <StackLayout Orientation="Horizontal">
                    <Label HorizontalOptions="FillAndExpand" VerticalOptions="Center" Text="Subject to Inspection?" />
                    <Switch x:Name="Inspection" />
                </StackLayout>

                <StackLayout Orientation="Horizontal">
                    <Label HorizontalOptions="FillAndExpand" VerticalOptions="Center" Text="Customer Delayed?" />
                    <Switch x:Name="Delayed" Toggled="DelayToggled" />
                </StackLayout>

                <StackLayout x:Name="ReasonRow" Orientation="Horizontal" IsVisible="true">
                    <Button Clicked="SelectReason" Text="Reason:" />
                    <Label HorizontalOptions="FillAndExpand" VerticalOptions="Center" x:Name="Reason"  />
                </StackLayout>

                <Image IsVisible="true" x:Name="CustomerSig" HeightRequest="75" BackgroundColor="White" Source="blank.png"  />
                <StackLayout Orientation="Horizontal" >
                    <Button Text="Customer Signature" Clicked="GetCustomerSignature" />
                    <Editor HeightRequest="35" VerticalOptions="Center" HorizontalOptions="FillAndExpand" x:Name="CustomerName" />
                </StackLayout>
                <Image IsVisible="true" x:Name="DriverSig" HeightRequest="75" BackgroundColor="White" Source="blank.png" />
                <StackLayout Orientation="Horizontal" >
                    <Button Text="Driver Signature" Clicked="GetDriverSignature" />
                    <Label VerticalOptions="Center" HorizontalOptions="FillAndExpand" x:Name="DriverName" Text="John Doe" />
                </StackLayout>
            </StackLayout>
        </ScrollView>
    </ContentPage.Content>

ActivityIndicator does not show AT ALL

$
0
0

I want to use a ActivityIndicator, basically for asynchronous actions to a server in a MVVM setup. I am trying that for the first time, it just won't go.

Now a lot could be wrong, but even in the SIMPLEST way it does not show AT ALL. I can see space is reserved on screen, but it stays invisible.
<ActivityIndicator Color="Black" IsVisible="True" IsRunning="True" IsEnabled="True" VerticalOptions="Center" HorizontalOptions="Center" HeightRequest="25" WidthRequest="25"/>
I have looked around on the web for any explanation or solution. But I gave up.

Is this a bug?

I have got Xamarin 4.2.2.11, Xamarin.Android 7.0.2.42.
Everything is up to date as far as I know.


How to Covert "18-10-2015 12:16:11" dateformat to "2015-10-18 12:16:11" in c#

$
0
0

My API is taking "2015-10-18 12:16:11" date format. But from enduser I am getting "18-10-2015 12:16:11" date format. So how to convert DD-MM-YYYY HH:MM:SS to YYYY-MM-DD HH:MM:SS

Remove extra space from listview

$
0
0

I am using two listview in my xaml page which are loading perfectly but takes unnecessary extra space which is not required. It affects layout. I have tried using footer but it didn't helped out. Please help to remove unnecessary space in listview. Here is code and Screenshot.

How to set DatePicker value equal yesterday in xaml in xamarin.form?

$
0
0

To set the Date attribute in xaml equal today we can use Today attribute as following:

xmlns:system="clr-namespace:System;assembly=mscorlib"
<DatePicker Date="{x:Static system:DateTime.Today}"/>

I've tried to set it by using AddDays method but it couldn't help.

<DatePicker Date="{x:Static system:DateTime.Today.AddDays(-1)}"/> Does not work.

So is there a way?

is there a Tabbed view in Xamarin.forms?

$
0
0

Hello,
any idea how to make a Tabbed view in xamarin.forms,
i only found Tabbed page which is not possible to put it inside a content page!

choosing Xamarin.forms is bad choice? should i've used each platforme beside with xamarin.android and xamarin.ios!

Thanks in advance

Linker Issue with Prism.Forms

$
0
0

I have been trying for a while now to achieve linking in mainly my Xamarin.Forms Android project.
I'm using Prism in my project and when i set the Linker to SDK and User assemblies I seem to receive exceptions surround the Prism framework.
After a certain point of debugging my output spits back not info on what caused the app to crash meaning I cannot narrow down what assembly is causing the issue.
Has anyone had any success with linking and Prism

Viewing all 91519 articles
Browse latest View live


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