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

GPS Location Enable in Xamarin forms

$
0
0

In Xamarin forms ,I have to enable GPS like as below image not in settings page


Touch and LongClick event on the same view in Android

$
0
0

Hi,

I have a use case with a Collectionview with custom views where a click/touch on a item will open a new page and a longclick will open a popup with some options for the view in the collection (remove, edit, etc).

From what I understand I can't implement this in Forms, I would have to use an effect or custom renderer. I thought I would be able to use the TouchEffect effect from the Xamarin documentation and its been working great for the Touch to open.
Now I would like to be able to use a LongClick/LongPress interaction as well. I've decided to modify the existing TouchEffect effect so that it also can fire a LongPressEvent. My TouchEffect class now looks like this:

public class TouchEffect : RoutingEffect
    {
        public event TouchActionEventHandler TouchAction;

        public event EventHandler<EventArgs> LongPressAction;

        public TouchEffect() : base("XamarinDocs.TouchEffect")
        {
        }

        public bool Capture { set; get; }

        public void OnTouchAction(Element element, TouchActionEventArgs args)
        {
            TouchAction?.Invoke(element, args);
        }

        public void OnLongPressAction(Element element, EventArgs args)
        {
            LongPressAction?.Invoke(element, args);
        }
    }

This works great in iOS, for the iOS platform effect I just added a UILongPressGestureRecognizer to the view and call the OnLongPressAction in its callback.

For Android I thought that I would be able to do the same and just add a callback to view.OnLongClick and call OnLongPressAction from there.
This does not seem to work since I also have a callback for view.OnTouch that sets the event.Handled to true, and setting event.Handled to false would mean that that other events like MotionEventActions.Up wont fire.

I read here that if I want to be able to use both OnClick and OnTouch that I would need a GestureDetector. Does that mean that I need a custom renderer? Is there any other way to solve this?
Any input would be greatly appreciated.

How to bind image source property to a list of strings programmatically?

$
0
0

I have a carouselView with images and i want to bind each image source property to a list of strings inside carouselView .

class Class1
        {
            public List<string> imageURL { get; set; }

            public Class1()
            {
                imageURL = new List<string>()
                {
                    "imgg1.jpg",
                    "imgg10.jpg",
                    "imgg11.jpg",
                };
            }
        } 

public MainPage()
        {
            InitializeComponent();

            Class1 class1 = new Class1();

            CarouselView carouselView = new CarouselView();
            carouselView.BindingContext = class1;
            carouselView.ItemsSource = class1.imageURL;
            carouselView.ItemTemplate = new DataTemplate(() =>
            {
                StackLayout stackLayout = new StackLayout();

                Image image = new Image();
                image.SetBinding(Image.SourceProperty, new Binding());

How to write properly the above SetBinding() function? For the first parameter Image.SourceProperty everything is clear, but for the second not really.

                stackLayout.Children.Add(image);
                return stackLayout;
            });

            s1.Children.Add(carouselView);
        }

Zoom-function for Cross-platform-project (Android, IOS, UWP)

Xamarin forms: Display Alert is not working in XF version 4.6 on UWP platform

$
0
0

For implementing expander on my project I have updated my XF version to 4.6.0.726. After that, the displayalert is not working on the xamarin UWP project. Working fine on android and ios platforms.

My Code:

await DisplayAlert("Alert","Hiiiii","Ok");

This is an issue with the XF new version, How can I solve this? I have uploaded a sample project here.

Button with text on an image

$
0
0

Hello,
I want to create a button with a background image and a label in the center. Now I am doing like this:

<Grid WidthRequest="150" HeightRequest="150">
    <ImageButton WidthRequest="150" HeightRequest="150" CornerRadius="75"
                 HorizontalOptions="Center" VerticalOptions="Center"
                 Source="{e:ImageResource MyNamespace.Images.my-image.png}" Aspect="AspectFill"/>
    <Label Text="2" TextColor="White" FontSize="Subtitle" FontAttributes="Bold"
           HorizontalOptions="Center" VerticalOptions="Center"/>
</Grid>

This has a problem: when I tap on the label the button is not clicked, I have to tap on the image outside the label to raise the event. Is it possible to add custom view or XAML code to button's content? Something like this:

<Button WidthRequest="150" HeightRequest="150" CornerRadius="75">
    <Grid WidthRequest="150" HeightRequest="150">
        <Image WidthRequest="150" HeightRequest="150" HorizontalOptions="Center" VerticalOptions="Center"
               Source="{e:ImageResource MyNamespace.Images.my-image.png}" Aspect="AspectFill"/>
        <Label Text="2" TextColor="White" FontSize="Subtitle" FontAttributes="Bold"
               HorizontalOptions="Center" VerticalOptions="Center"/>
    </Grid>
</Button>

Xamarin iOS Tool exited with code1: Output: ditto: Can't get real path for source

$
0
0

I added a Notification Service Extension project to my Xamarin project. Then I added a reference to it in the Xamarin main iOS project. When building i get this error:

Severity Code Description Project File Line Suppression State Error Tool exited with code: 1. Output: ditto: can't get real path for source '../../NotifServiceExtension/ac83d35a0ee368097132b3463a52c5b0/bin/iPhone/Debug/NotifServiceExtension.appex' SARR1.iOS

Any ideas please?

Identify GPS is enabled or not

$
0
0

Dear Team,

I would like to place a prompt where it identifies if user has disabled GPS or not. If GPS is enabled, I would like to open a page. If its disbaled, I would like to show a prompt to tell user to enable GPS and then open. Please let me know how to acheive the same


X and Y position for button not working

$
0
0

Hello,

I made some updates and since that, the Y position of my buttons are broken.

For example the X and Y of my image button is

X : 211
Y : 0

Wich make no sens.

I think this bug is due to the Shell page.

Any idea to counter this issue ?

How to get current instance of viewmodel in prism

$
0
0

I am trying to implement prism mvvm framework in my app.
I want to get current instance of viewmodel in another viewmodel.
How can I achieve it ?

The case is : I have three pages, PageA, PageB and PageC.
Navigations are performed as - PageA > PageB > PageC
Now I want to update the property of PageAViewModel from PageCViewModel, So that when I go back to PageA, it should also update the view.

App rejection from App Store due to UIWebView

$
0
0

Hi Team,

I need some urgent help as my app is getting rejected from apple store continuously for making use of UIWebView. My app is build using Xamarin forms and i have updated xamarin forms to the latest version, also added m-touch arguments --optimize=experimental-xforms-product-type. Even after making these changes, app gets rejected from app store.

Please suggest.

Thanks,
Akhil Mittal

App rejected due to use of UIWebView - Xamarin Forms

$
0
0

Hi Team,

I need some urgent help as my app is getting rejected from apple store continuously for making use of UIWebView. My app is build using Xamarin forms and i have updated xamarin forms to the latest version, also added m-touch arguments --optimize=experimental-xforms-product-type. Even after making these changes, app gets rejected from app store.

Please suggest.

Thanks,
Akhil Mittal

Collection and ViewStateManager

$
0
0

I have a page with a atcklayout that contains a collectionviewand followed by another stacklayout. I have followed this

https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/collectionview/selection#change-selected-item-color

to change the selection backgroundcolor but it changes the backgroundcolor of the stacklayouot as well. I guess the stacklayouts "state" is "normal" so it uses the normal state color. That is because you define the VSM relative to the root element on the page. Targetting the second stacklayout doesn;t wrk either. any suggestions?

How do I to create an infinite ListView in Xamarin?

$
0
0

I have many records on database, next to 5000 records on a table and to get this informations I am trying to use OFFSET and LIMIT at my webservice, it works well. On Xamarin I am trying to create an infinite ListView that will loading data while user make the scroll. The problem that I cannot do this works.

How do I to fix this ?

XAML

<?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"
             x:Class="MyApp.View.LimitOffsetTest">

    <ContentPage.Content>

        <StackLayout>            

            <ListView x:Name="MyList" ItemAppearing="OnItemAppearing" VerticalOptions="FillAndExpand">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <StackLayout>
                                <Label Text="{Binding numero}"></Label>
                                <Label Text="{Binding valor}"></Label>
                            </StackLayout>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>              

            </ListView>

            <StackLayout HorizontalOptions="FillAndExpand" BackgroundColor="Yellow">
                <Label x:Name="FooterLoading" Text="Loading..." IsVisible="False" TextColor="Red" FontAttributes="Bold" HorizontalOptions="Center"></Label>
            </StackLayout>

        </StackLayout>

    </ContentPage.Content>

</ContentPage>

LimitOffsetTest

public partial class LimitOffsetTest : ContentPage{
        private SmartCollection<NumerosSorteioDTO> smartCollection;

        private static ConcursoDTO _values = new ConcursoDTO();
        private static int OFFSET = 0;
        private const int LIMIT = 5;

        public LimitOffsetTest(){
            InitializeComponent();

            firstLoad();

        }

        private void firstLoad(){
            try{

                FooterLoading.IsVisible = true;

                smartCollection = new SmartCollection<NumerosSorteioDTO>();

                _values.offset = OFFSET;
                _values.limit = LIMIT;
                ConcursoDTO dto = ConcursoService.GetNumerosSorteConcursoLO(_values);
                smartCollection.AddRange(dto.numeros);
                this.BindingContext = smartCollection;
                this.MyList.ItemsSource = smartCollection;

            }catch(Exception e){
                Debug.WriteLine("Erro: " + e.Message);
            }
            finally{
                FooterLoading.IsVisible = false;
            }


        }

        private void OnItemAppearing(object sender, ItemVisibilityEventArgs args){

            try{
                FooterLoading.IsVisible = true;

                var _item = (NumerosSorteioDTO)args.Item;
                if (_item == smartCollection[smartCollection.Count - 1])
                {
                    _values.offset += 5;
                    ConcursoDTO dto = ConcursoService.GetNumerosSorteConcursoLO(_values);
                    smartCollection.AddRange(dto.numeros);
                }


            } catch(Exception e){
                Debug.WriteLine("Erro: " + e.Message);
            }finally{
                FooterLoading.IsVisible = false;
            }

        }




    }//class

Controller

public class SmartCollection<T> : ObservableCollection<T>
{
    public SmartCollection()
        : base()
    {
    }

    public SmartCollection(IEnumerable<T> collection)
        : base(collection)
    {
    }

    public SmartCollection(List<T> list)
        : base(list)
    {
    }

    public void AddRange(IEnumerable<T> range)
    {
        foreach (var item in range)
        {
            Items.Add(item);
        }

        this.OnPropertyChanged(new PropertyChangedEventArgs("Count"));
        this.OnPropertyChanged(new PropertyChangedEventArgs("Item[]"));
        this.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
    }

    public void Reset(IEnumerable<T> range)
    {
        this.Items.Clear();

        AddRange(range);
    }
}

Geolocation.GetLocationAsync Android

$
0
0

Hi All,

I'm having a random weird issue with Geolocation.GetLocationAsync.

When I am calling var getLastKnownLocation = await geoLocation.GetLastKnownLocation(); within an action on some devices, it constantly hangs on Geolocation.GetLocationAsync(request); without anytime or Exception and doesnt move!

One device this does this on is a Huawei P30 Pro, Android Version 9.

My code is below.

    public async Task<LocationViewModel> GetLastKnownLocation()
    {
        try
        {
            var mn = new LocationViewModel();

            var request = new GeolocationRequest(GeolocationAccuracy.Medium, TimeSpan.FromSeconds(5));

            var location = await Geolocation.GetLocationAsync(request);

            if (location != null)
            {
                mn.Latitude = location.Latitude.ToString();
                mn.Longitude = location.Longitude.ToString();

                return mn;
            }

            return new LocationViewModel()
            {
                Longitude = "",
                Latitude = ""
            };              
        }
        catch (FeatureNotSupportedException fnsEx)
        {
            return new LocationViewModel()
            {
                Longitude = "",
                Latitude = ""
            };
        }
        catch (FeatureNotEnabledException fneEx)
        {
            return new LocationViewModel()
            {
                Longitude = "",
                Latitude = ""
            };
        }
        catch (PermissionException pEx)
        {
            return new LocationViewModel()
            {
                Longitude = "",
                Latitude = ""
            };
        }
        catch (Exception ex)
        {
            return new LocationViewModel()
            {
                Longitude = "",
                Latitude = ""
            };
        }
    }

Thanks,
Dane


Preloading a webview in a TabbedPage

$
0
0

I have a TabbedPage with two pages, one is holding a NavigationPage and the other is holding a ContentPage with a WebView control.

When the app loads the NatigationPage is the active page, but I need to meanwhile preload the WebView.
I'm not sure how to achieve this as I noticed that the WebViewRenderer only gets created after activating the WebView's page for the first time.

Is there a way to activate that page without actually navigating to it?

CollectionView background color not highting when add the items to the list

$
0
0

Hi, i am using collectionview for selecting multile items. when select the items, background color is coming.but my problem is when add the items to the list , now not getting the background color for iOS . working fine in android .i used in two ways but no luck.

  1. in ViewMode
    var items= ListOfScanTest.Where(x => x.ScanTestsName == SendAppointmentData.Rscantest).ToList();
    SelectedListOfScanTest = items;

  2. in .cs
    collectionList.SelectedItems = SelectedListOfScanTest .Cast < object > ().ToList();

in XAML

please any one help me out from this issue

How to create a cross platform map page with Pins and click events using the Open Street Maps.

$
0
0

I have been trying to create a map UI using Xamarin Forms aiming Android and iOS , using OSM. Implemented using the below https://github.com/charlenni/OsmSharp.Forms. Able to get the Map successfully and even able to add Points as circles. But I would prefer to add Image similar to Pins and also need to to display a infowindow on the click of those images, further on click of those info windows, get navigated to next Screens.

Please suggest me a way that could be handled in Xamarin.Forms.

Thanks
Vidhya A

how to hide Stacklayout inside listview

$
0
0

I have two Stacklayout in listview, I want to hide/ show the second Stacklayout on clicking list item what is the way to this?

FlyoutItem Icons Display in Android Emulator but not on physical device

$
0
0

I'm relatively new to Xamarin. Working with a "Shell" template application and Forms 4.6.0.726.

Created embedded resources and ImageResourceExtension class as documented. Confirmed resources loading via debug console and by placing same resource on a ContentPage where it does display on the device. So I know the images are available. Also another embeddedresource image IS displaying in the FlyoutHeader

In the Android emulator the flyout icon displays as expected. On a Pixel XL 2 (Android 10) however, the icon does not display -- actually sometimes it flashes for a very brief moment, but 99% of the time is not visible. Also taps on the flyoutitems are sometimes unresponsive (on the device, not in the emulator).

Xaml sample:

<FlyoutItem Title="Home" Icon="{utils:ImageResource MyXamApp.Resources.Images.home_16x.png}"  >
    <ShellContent>
        <local:DashboardView/>
    </ShellContent>
</FlyoutItem>

Any suggestions/ideas appreciated.

Thanks.

DD

Viewing all 89864 articles
Browse latest View live


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