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

Best way to handle screen rotation in CollectionView

$
0
0

I currently have this issue in my CollectionView.

I have a grouped list displayed in my app, when the screen rotates the items that are not visible are changed to the right width but not the ones visible. What could be the best approach to fix this without the need of refreshing the whole page?

Code:

<RelativeLayout BackgroundColor="Transparent">
                <Label
                    Margin="{StaticResource HeaderLabelMargin}"
                    FontFamily="{DynamicResource MontserratBold}"
                    FontSize="Medium"
                    HorizontalTextAlignment="Center"
                    IsVisible="{Binding IsListEmpty}"
                    RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent,
                                                                           Property=Height,
                                                                           Factor=1}"
                    RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent,
                                                                          Property=Width,
                                                                          Factor=1}"
                    Text="{xt:Translate no_combos}"
                    VerticalTextAlignment="Center" />
                <CollectionView
                    IsGrouped="True"
                    IsVisible="{Binding IsListEmpty, Converter={xt:ValueBoolInverseConverter}}"
                    ItemsSource="{Binding ComboList}"
                    RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent,
                                                                           Property=Height,
                                                                           Factor=1}"
                    RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent,
                                                                          Property=Width,
                                                                          Factor=1}"
                    SelectionMode="None">
                    <CollectionView.Header>
                        <StackLayout>
                            <Label
                                Margin="{StaticResource HeaderLabelMargin}"
                                FontFamily="{DynamicResource MontserratBold}"
                                FontSize="Medium"
                                HorizontalOptions="Center"
                                Text="{xt:Translate character_facing_right}" />
                            <Picker />
                        </StackLayout>
                    </CollectionView.Header>
                    <CollectionView.GroupHeaderTemplate>
                        <DataTemplate x:DataType="models:ComboCategoryView">
                            <StackLayout>
                                <sfBorder:SfBorder
                                    Margin="{StaticResource HeaderBorderMargin}"
                                    BackgroundColor="{StaticResource AccentColor}"
                                    BorderColor="{StaticResource ButtonBorderColor}"
                                    BorderWidth="{StaticResource HeaderBorderWidth}"
                                    CornerRadius="{StaticResource HeaderBorderCornerRadius}">
                                    <Label
                                        Margin="{StaticResource StandardSpacing}"
                                        FontFamily="{DynamicResource MontserratBoldItalic}"
                                        FontSize="Medium"
                                        Text="{Binding Category}" />
                                </sfBorder:SfBorder>
                            </StackLayout>
                        </DataTemplate>
                    </CollectionView.GroupHeaderTemplate>
                    <CollectionView.ItemTemplate>
                        <DataTemplate x:DataType="models:ComboView">
                            <controls:ComboItem
                                Title="{Binding Title}"
                                Combo="{Binding Combo}"
                                Comment="{Binding Comment}"
                                IsStock="{Binding IsStock}"
                                Type="{Binding Type}"
                                UniqueId="{Binding UniqueId}" />
                        </DataTemplate>
                    </CollectionView.ItemTemplate>
                    <CollectionView.Footer>
                        <ContentView Margin="{StaticResource FooterSpacing}" />
                    </CollectionView.Footer>
                    <CollectionView.EmptyView>
                        <StackLayout>
                            <Label
                                Margin="{StaticResource HeaderLabelMargin}"
                                FontSize="Medium"
                                HorizontalOptions="Center"
                                Text="{xt:Translate no_combos}" />
                        </StackLayout>
                    </CollectionView.EmptyView>
                </CollectionView>
                <sfBorder:SfBorder
                    Margin="{StaticResource StandardSpacing}"
                    BackgroundColor="{StaticResource PrimaryColor}"
                    BorderColor="{StaticResource ButtonBorderColor}"
                    BorderWidth="{StaticResource ButtonBorderWidth}"
                    CornerRadius="{StaticResource ButtonBorderRadius}"
                    RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent,
                                                                      Property=Width,
                                                                      Factor=1,
                                                                      Constant={StaticResource ButtonRelativeConstant}}"
                    RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent,
                                                                      Property=Height,
                                                                      Factor=1,
                                                                      Constant={StaticResource ButtonRelativeConstant}}">
                    <Button
                        BackgroundColor="Transparent"
                        Clicked="Handle_AddCombo_Clicked"
                        FontSize="Large"
                        HeightRequest="{StaticResource ButtonSize}"
                        Text="+"
                        TextColor="{StaticResource MainTextColor}"
                        WidthRequest="{StaticResource ButtonSize}" />
                </sfBorder:SfBorder>
                <sfBusyInd:SfBusyIndicator
                    AnimationType="Box"
                    IsVisible="{Binding IsBusy}"
                    RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent,
                                                                           Property=Height,
                                                                           Factor=1}"
                    RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent,
                                                                          Property=Width,
                                                                          Factor=1}"
                    ViewBoxHeight="{StaticResource IndicatorSize}"
                    ViewBoxWidth="{StaticResource IndicatorSize}" />
            </RelativeLayout>

Selected Item FontAtrributes in Listview

$
0
0

Hi,
I am try to change the FontAtrribute to None when user taps on an Item(LblSubject) in a Listview.
My problem is that i have allready bind the FontAtrributes of that item and used a converter to be able to get
the text in bold or none on Listview loading.
Now i want to change the text to none when item is selected but i cant find a way.
Here my code

My XAML

            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <ViewCell.View>
                            <!--<StackLayout Padding="30,0,0,0" BackgroundColor="#E6E6E6" >-->
                            <StackLayout Padding="30,0,0,0">
                                <Label x:Name="LblSubject" Text= "{Binding Title,StringFormat='Title : {0}'}" FontAttributes="{Binding Messages,Converter={StaticResource UnreadToBold}}"/>
                                <Label Text="{Binding DateTimeCreatedUtc,StringFormat='DateTime : {0}',Converter={StaticResource UtcToLocal}}"
                                       TextColor="Gray" 
                                       FontSize="Micro" />
                                <!--<Label x:Name="lbltest" Text="{Binding IsRead}" />-->
                            </StackLayout>
                        </ViewCell.View>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

Converter UnreadToBold
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
bool returnValue = true;
foreach (var casemessage in (dynamic)value)
{
CaseMessage CaseMessage = casemessage;

            if (!CaseMessage.IsRead)
                returnValue = false;


        }
        return ((bool)returnValue) ? FontAttributes.None : FontAttributes.Bold;

Thank you for any help

UPDATE
I also tried to bind the SelectedItem of the Listview and use a converter but no success.

Xamarin.Forms iOS App Crashes on tapping inside Entry control after Latest update to 4.3.0.99

$
0
0

Hi

My Xamarin.Forms iOS app is crashing while i tap on Entry control for typing. It happened after i updated to latest 4.3.0 from 3.6 version.
The error i see in output window & Error log file is this "The app has been terminated.
Failed to Stop app: An error occurred on client IDB1630281 while executing a reply for topic xvs/idb/16.3.0.281/stop-app"

Unable to understand the cause of this crash. I have attached error log file if anyone wants to view.

I am using Visual Studio 2019.

I have spent more than a week in fixing various issues after this update and able to run the app but now it crashes on above scenario.

Is anyone facing similar issue around or can anyone help me understand the cause?

Note: There is no change in the Xamal or code. It's all happening after the update. It was working fine with previous version 3.6 update.

(Object reference not set to an on object) on the OnStart() method in App.xaml.cs

$
0
0

For the first time i'm executing the app I notice and error on the App.xaml.cs method OnStart() that only gives me the following reference:
System.NullReferenceException: Object reference not set to an instance of an object. occurred
I still don't understand why the cause of the error or why it happened.

How to use AppCenter's API progrmaticallly?

$
0
0

Hi, I am working on xamarin forms, where I am trying to consume AppCenter's to send a notification to specific users. I want to use referring the Microsoft swagger documentation. https://openapi.appcenter.ms/#/ before accessing those API I need to do authorization. For that, I tried the following function.

    async Task SignInAsync()
    {
        try
        {
            // Sign-in succeeded, UserInformation is not null.
            UserInformation userInfo = await Auth.SignInAsync();

            // Get tokens. They are not null.
            string idToken = userInfo.IdToken;
            string accessToken = userInfo.AccessToken;

            // Do work with either token.
        }
        catch (Exception e)
        {
            // Do something with sign-in failure.
        }
 }

It is going to catch block saying auth is disabled. I enabled auth programmatically by using

Auth.SetEnabledAsync(true);

but it is not working. Is this the right way to access the AppCenter API or another way is there?

Toolbar item on the left side

$
0
0

Hi,

Is it possible to specify Toolbar item to be on the left side or do I need custom renderer?

Call an Android Activity from PCL

$
0
0

Hi,

I am relatively new to Xamarin.Forms and am currently working on a cross-platform app. Part of the app requires videos to be played using Brightcove's Player SDK (Java classes). I have created a Binding Project for this and am able to play videos on Android.

My views are created in the PCL of my app but the Brightcove SDK is native so I have developed an Android Activity to implement the Player. What I am now trying to do is find a way to run that Activity as part of one of my views, i.e. when someone clicks a particular button on the app the Activity will run and play a video as the top half of one of my PCL views.

I was just wondering if anyone has any guidance on the best way to do this? Any advice is appreciated.

Thanks very much,
Stephen.

How to hide some Shell tabs?

$
0
0

Hi, I'm using Shell to create a Flyout menu with 4 items but I want to display only 3 of them on the bottom bar.

Seems like IsTabStop could be used to achieve this but it does not do anything when I add it.

This is the code I have:

<FlyoutItem Title="Menu" FlyoutDisplayOptions="AsMultipleItems">
    <Tab Title="Item 1" Icon="icon1.png">
        <ShellContent>
            <views:PageOne />
        </ShellContent>
    </Tab>
    <Tab Title="Item 2" Icon="icon2.png">
        <ShellContent>
            <views:PageTwo />
        </ShellContent>
    </Tab>
    <Tab Title="Item 3" Icon="icon3.png">
        <ShellContent>
            <views:PageThree />
        </ShellContent>
    </Tab>
    <Tab Title="Item 4" Icon="icon4.png">
        <ShellContent>
            <views:PageFour />
        </ShellContent>
    </Tab>
</FlyoutItem>

I have tried using MenuItem as that adds an item to the Flyout but it does not show it up on the bottom bar. However, this only works if I want my last item to be excluded from the the bottom bar. What is the best way to hide an item in the middle this?



Xamarin forms - IOS image does not share to whatsapp and Facebook

$
0
0

I have xamarin forms application. It has a feature to share captured/galary images. It works well for Xamarin Android but for Xamarin IOS while i share images to whatsapp/facebook then it shares only text and skip sharing image.
Please check below code and suggest if it can be fixed:

public async Task Share(string title, string message, ImageSource imageSource)
{

        IImageSourceHandler handler;
        if (imageSource is FileImageSource)
            handler = new FileImageSourceHandler();
        else if (imageSource is StreamImageSource)
            handler = new StreamImagesourceHandler();
        else if (imageSource is UriImageSource)
            handler = new ImageLoaderSourceHandler();
        else
            throw new NotImplementedException();
        var uiImage = await handler.LoadImageAsync(imageSource);
        var img = NSObject.FromObject(uiImage);


       // var items = new NSObject[] { NSObject.FromObject(message), img };
        var items = new NSObject[] {  img };
        var activityController = new UIActivityViewController(items, null);
        var vc = GetVisibleViewController();

        NSString[] excludedActivityTypes = null;

        if (excludedActivityTypes != null && excludedActivityTypes.Length > 0)
            activityController.ExcludedActivityTypes = excludedActivityTypes;

        if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
        {
            if (activityController.PopoverPresentationController != null)
            {
                activityController.PopoverPresentationController.SourceView = vc.View;
            }
        }
        await vc.PresentViewControllerAsync(activityController, true);
    }

    UIViewController GetVisibleViewController()
    {
        var rootController = UIApplication.SharedApplication.KeyWindow.RootViewController;

        if (rootController.PresentedViewController == null)
            return rootController;

        if (rootController.PresentedViewController is UINavigationController)
        {
            return ((UINavigationController)rootController.PresentedViewController).TopViewController;
        }

        if (rootController.PresentedViewController is UITabBarController)
        {
            return ((UITabBarController)rootController.PresentedViewController).SelectedViewController;
        }

        return rootController.PresentedViewController;
    }
} 

Thanks,

Is there any way to remove navigationpage default back "

$
0
0

hello ,
i am trying to remove navigation page back button with NavigationPage.SetHasNavigationBar(some page, true) but its not working.

GPS and Wifi sensor compatibility - Xamarin forms android & ios

$
0
0

Hi everyone !

I develop an mobile application on Android and IOS with Xamarin forms which get sensor data with wifi and gps data with the phone( gps data come from mobile and not from wifi sensor).

My app work pretty fine on android but on IOS, when I connect my wifi sensor to log sensor data and in same time I log gps data from phone, the app or the system believe my wifi sensor bring data & internet, so it try to get fine gps position by the wifi....

But you understand, my wifi sensor just bring acceleration data but not internet....

On android, automaticly the system understand the wifi don't bring internet so it don't use to calculate the gps position and it only use phone gps which is what I want....

How is it possible to ask to my app to calculate GPS position without wifi ?

Do you know if it's possible to indicate my wifi don't bring internet and so I prefer to use 3G/4G to have internet ?

I stay tuned if you need more information....

Thanks !

Xamarin forms: Webview for playing video is not working in iPhone?

$
0
0

I am using Webview for playing video and audio and it is working fine on android and iPhone simulators. But on the real iPhone, video playing is not working fine.

For playing the video on the iPhone, I need to tap the video play button multiple times. After that also it takes a long time to play the video. Another important thing is my video links have no video format(.mp4,.mkv).

XAML

<WebView 
    x:Name="web_view"
    HeightRequest="200"
    WidthRequest="200"
    HorizontalOptions="FillAndExpand"
    VerticalOptions="FillAndExpand"/>

XAML.cs

web_view.Source = "https://player.vimeo.com/video/303543322";

I tried Plugin.MediaManager.Forms, but it needs video format(.mp4,.mkv) in the link, otherwise it will not work. So is there any way to fix this issue in webview itself or should I go for any other player(video and audio) which supports playing video without video format?

horizontal collectionview inside the horizontal collection view

$
0
0

Hi,

I'm using Xamarin.Forms Latest version
and using collection view for binding the repeated tiles in my project

i'm using horizontal collectionview inside the horizontal collection view and that creates a laggy scrolling in that

Get device region in xamarin forms.

$
0
0

How can I get the device region (not the device language) of a device?

both
var region = RegionInfo.CurrentRegion.ToString().ToUpper();
and
var r = System.Globalization.CultureInfo.CurrentUICulture.Name;
doesn't return the region.

Thanks

How to Play Youtube Video using youtube url in xamarin forms?

$
0
0

Hlo Everyone,

I want to play youtube video play in Video Player using youtube url in Xamarin forms without using webview .


Why don't set image from url?

$
0
0

Don't set image from url. Permission INTERNET is enabled, i already deleted bin and obj files. No errors.
Image.Source = "site.com/image.png"

Developing FCM Push notifications in Xamarin.Forms

$
0
0

I have already developed push notifications for Xamarin.Android & Xamari.iOS. How can this help me to develop notifications in Xamarin.Forms?

How to implement ShimmerLayout in Xamarin Forms ?

Local Notifications for a Cross Platform app

$
0
0

Hi All,

I'm am learning Xamarin.Forms and have been at it for just over a week now, and i should just say that these are my first steps into app development using Xamarin.

I want to write a cross platform app so I can release on Android as well as iOS, but I'd also like to use the Xamarin.iOS local notification system. I dont even know if Android has such a thing, but if it does, I'd like to use that too.

I found this guide on how to do this (for iOS) using Xamarin.iOS and even got the example working on my PC/MacBookPro combination using Visual Studio 2017 on my PC, and must say the code looks a little alien to me, and doesn't reflect the Xamarin.Forms way of doing things at all.

Is there a simple way of re-engineering an example (this one in particular) from Xamarin.iOS to Xamarin.Forms?

Also Are there any good guides out there on how to replicate this for Android using Xamarin.Forms?

The guide I followed is shown below, and is a https link... (The link may or may not work, Apparently I'm too green to post links yet)

developer.xamarin.com/guides/ios/platform_features/user-notifications/deprecated/local_notifications_in_ios_walkthrough/

How do i download a string from a url in Xamarin.Forms

$
0
0

I previously managed to download a string in Xamarin.Android like this:
using (WebClient client = new WebClient()) { var TheString = client.DownloadString("http://www.topentwelonline.nl/json/news.json"); }
but WebClient isn't supported in xamarin.forms, so how can i achieve this?

Viewing all 77050 articles
Browse latest View live


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