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

SfBadgeView BadgeText change value

$
0
0

hi

how SfBadgeView BadgeText change value?

<ContentPage.ControlTemplate>

            <controls:TitleView BackgroundColor="#690a3d" Margin="0" Padding="0">
                <controls:TitleView.LeadingView>
                    <ImageButton Source="BulletedList" HeightRequest="25" BackgroundColor="Transparent" WidthRequest="25" Clicked="SfButton_OnClicked" Grid.Column="0"/>
                </controls:TitleView.LeadingView>
                <controls:TitleView.TrailingView>
                    <StackLayout HorizontalOptions="EndAndExpand" Orientation="Horizontal" BackgroundColor="Transparent">
                        <StackLayout>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition />
                                    <ColumnDefinition />
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>

                                <Image Source="User" Margin="0,0,5,0" BackgroundColor="Transparent" Grid.Column="2"/>

                                <badgeView:SfBadgeView x:Name="Bag1" Grid.Column="1" HorizontalOptions="Center" BadgeText="{Binding TedadDarBag}" VerticalOptions="Center">
                                    <badgeView:SfBadgeView.Content>
                                        <Image Source="ShoppingCart" BackgroundColor="Transparent" />
                                    </badgeView:SfBadgeView.Content>
                                    <badgeView:SfBadgeView.BadgeSettings>
                                        <badgeView:BadgeSetting BadgeType="Error" />
                                    </badgeView:SfBadgeView.BadgeSettings>
                                </badgeView:SfBadgeView>

                                <Image Source="Search" Margin="5,0,0,0" BackgroundColor="Transparent" Grid.Column="0"/>
                            </Grid>
                        </StackLayout>
                    </StackLayout>
                </controls:TitleView.TrailingView>
            </controls:TitleView>

            <ContentPresenter />
        </StackLayout>
    </ControlTemplate>
</ContentPage.ControlTemplate>

not working BadgeText="{Binding TedadDarBag}"


Xamarin Forms: Push notification is not receiving to ios device

$
0
0

I have done the following things:

  1. Created a project in FCM console and added ios project into it.
  2. Downloaded the GoogleService-Info.plist and added it to the xamarin forms ios project directory and set the build action as Bundlesource.
  3. On Info.plist enabled remote notification background mode.
  4. Added FirebaseAppDelegateProxyEnabled in the app’s Info.plist file and set it to No.
  5. Created a provisioning profile and distribution certificate and installed it into the keychain access. Also, mapped these certificates in the project options.
  6. Uploaded .p12 certificate in FCM console.
  7. Added codes for handling push notification in AppDelegate.cs.

My Code:

    [Register("AppDelegate")]
    public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
    {
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init();
            LoadApplication(new App("",""));
            RequestPushPermissionsAsync();
            _launchoptions = options;
            return base.FinishedLaunching(app, options);
        }
        NSDictionary _launchoptions;
        public override void OnActivated(UIApplication uiApplication)
        {
            base.OnActivated(uiApplication);
            if (_launchoptions != null && _launchoptions.ContainsKey(UIApplication.LaunchOptionsRemoteNotificationKey))
            {
                var notfication = _launchoptions[UIApplication.LaunchOptionsRemoteNotificationKey] as NSDictionary;
                PresentNotification(notfication);
            }
            _launchoptions = null;
        }

        async Task RequestPushPermissionsAsync()
        {
            var requestResult = await UNUserNotificationCenter.Current.RequestAuthorizationAsync(
                 UNAuthorizationOptions.Alert
                | UNAuthorizationOptions.Badge
                | UNAuthorizationOptions.Sound);

            bool approved = requestResult.Item1;
            NSError error = requestResult.Item2;
            if (error == null)
            {
                if (!approved)
                {
                    Console.Write("Permission to receive notification was not granted");
                    return;
                }

                var currentSettings = await UNUserNotificationCenter.Current.GetNotificationSettingsAsync();
                if (currentSettings.AuthorizationStatus != UNAuthorizationStatus.Authorized)
                {
                    Console.WriteLine("Permissions were requested in the past but have been revoked (-Settings  app)");
                    return;
                }
                UIApplication.SharedApplication.RegisterForRemoteNotifications();
            }
            else
            {
                Console.Write($"Error requesting permissions: {error}.");
            }
        }

        public async override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
        {
            if (deviceToken == null)
            {
                return;
            }
            Console.WriteLine($"Token received: {deviceToken}");
            await SendRegistrationTokenToMainPRoject(deviceToken);
        }

        async Task SendRegistrationTokenToMainPRoject(NSData deviceToken)
        {
            MessagingCenter.Send<object, string>(this, "fcmtoken", deviceToken.ToString());
        }

        public override void FailedToRegisterForRemoteNotifications(UIApplication application, NSError error)
        {
            Console.WriteLine($"Failed to register for remote notifications: {error.Description}");
        }

        public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo,
            Action<UIBackgroundFetchResult> completionHandler)
        {
            PresentNotification(userInfo);
            completionHandler(UIBackgroundFetchResult.NoData);
            try
            {
                UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;
                NSDictionary aps = userInfo.ObjectForKey(new NSString("aps")) as NSDictionary;
                var message = (aps[new NSString("webContentList")] as NSString).ToString();
                LoadApplication(new App("", message));
            }
            catch (Exception ex)
            {
                //LogInfo.ReportErrorInfo(ex.Message, ex.StackTrace, "AppDelegate-DidReceiveRemoteNotification");
            }
        }

        void PresentNotification(NSDictionary userInfo)
        {
            NSDictionary aps = userInfo.ObjectForKey(new NSString("aps")) as NSDictionary;

            var msg = string.Empty;

            if (aps.ContainsKey(new NSString("alert")))
            {
                msg = (aps[new NSString("alert")] as NSString).ToString();
            }
            if (string.IsNullOrEmpty(msg))
            {
                msg = "(unable to parse)";
            }
            MessagingCenter.Send<object, string>(this, App.NotificationReceivedKey, msg);
        }
    }

I am not using any NuGet packages in ios part. When running the project into a device, the FCM token generating part is working and I can see the fcm token on the VS console. I tried to send a test notification to a device from postman but getting InvalidRegistration error.

Postman Response

{
    "multicast_id": 8754155136812875313,
    "success": 0,
    "failure": 1,
    "canonical_ids": 0,
    "results": [
        {
            "error": "InvalidRegistration"
        }
    ]
}

Postman Body

 {
    "to" : "d20ad003 7473bfba 85dffc33 1534decf b4b886f1 c738878f fd7f2c60 d9dabc36",
 "collapse_key" : "type_a",
 "data" : {
     "body" : "Body of Your Notification in Data",
     "title": "Title of Your Notification in Title",
     "key_1" : "Value for key_1",
     "key_2" : "Value for key_2"
 },
 "notification" : {
     "body" : "Body of Your Notification",
     "title": "Title of Your Notification",
     "sound": "default",
     "content_available" : true
 }
}

I have completed the android part implementation and notifications are receiving when push from the postman. But getting InvalidRegistration error on postman and not receiving any notification in my ios device.

Anyone suggest a solution for this issue.

Thanks in advance.

Gesturerecognizer binding to command in complex layout

$
0
0
 I have a complex page layout:
        <ContentPage.Content>
               <StackLayout >
                        <ScrollView >
                            <FlexLayout BindableLayout.ItemsSource="">
                                <BindableLayout.ItemTemplate>
                                    <DataTemplate>
                                                <components:SomeComponent />

                                    </DataTemplate>
                                </BindableLayout.ItemTemplate>
                            </FlexLayout>
                        </ScrollView>
                </StackLayout>
            </ContentPage.Content>

Then there is component definition:

    <StackLayout xmlns="http://xamarin.com/schemas/2014/forms"
            xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml x:Class="XXX.Components. SomeComponent">
            <AbsoluteLayout>
        .....
        </AbsoluteLayout>
        <StackLayout.GestureRecognizers>
            <TapGestureRecognizer Command="{Binding BindingContext.GoToDetailCommand}"
                                  CommandParameter="{Binding SomeID}"/>
        </StackLayout.GestureRecognizers>
    </StackLayout>

In my case I am unable to fire Tap gesture. I suspect that FlexLayout BindableLayout.ItemsSource="{Binding XXX}" is binding to specific observable collection, so in component Binding BindingContext.GoToDetailCommand actually does not exist (they are defined in initial viewmodel for this page).
Can you please advise how to sort this issue?

Dino

Changing label text in shell flyout header from content page

$
0
0

I am trying to develop a shell with login option and certain menu options after login. The menu options are kept in flyout.

<Shell.FlyoutHeader>



</Shell.FlyoutHeader>

<FlyoutItem Route="Menu" Title="Menu" Shell.TabBarIsVisible="False" FlyoutDisplayOptions="AsMultipleItems">
    <ShellContent Route="Opt1" Title="Option 1" Icon="1.png" IsTabStop="True" ContentTemplate="{DataTemplate local:Opt1}" />
    <ShellContent Route="Opt2" Title="Option2" Icon="2.png" IsTabStop="True" ContentTemplate="{DataTemplate local:Opt2}" />
</FlyoutItem>

I want to pass the login name to flyout header. But since the shell page loads first and then it moves to login page, no value is passed to it. What could be possible solution

Thanks

Is UWP support for Xamarin.Forms going to have a slow and painful death

$
0
0

So have to ask,

In VS2019 there is no option to create the project with UWP only iOS and Android.
In Xamarin.Forms new features such as Visual and Shell only support iOS and Android.

Slow death march for UWP? Sounds like silverlight all over again.

Guys, come clean early and soon or we will need to look for yet another provider.

Re-Order ListView Items with Drag & Drop

$
0
0

Hello,
Is there a function or property to add to a Listview to be able to re-order items by drag and drop?
I did not find anything in the Xamarin documentation, and the solutions found on the forums to work around the problem do not work or are very complicated to implement.
Thank you for helping me, this feature is essential for the application I am developing.

How to avoid PushModalAsync from retrieving variable values from earlier calls?

$
0
0
Hello there, in my Xamarin forms application I have a button that opens another ContentPage by calling “Navigation.PushModalAsync(new Class());” said class contains public variables with default values that get modified during the usage of the application. My issue is whenever the back button is pressed on Android, and the button is re-pressed, instead of the contentpage showing up with its default values, it shows up with the old values from last time it was open, despite me creating a new instance of the class every time PushModalAsync is called. I’ve tried a lot of different things but nothing seems to work.

How to avoid PushModalAsync from retrieving variable values from earlier calls?

$
0
0
Hello there, in my Xamarin forms application I have a button that opens another ContentPage by calling “Navigation.PushModalAsync(new Class());” said class contains public variables with default values that get modified during the usage of the application. My issue is whenever the back button is pressed on Android, and the button is re-pressed, instead of the contentpage showing up with its default values, it shows up with the old values from last time it was open, despite me creating a new instance of the class every time PushModalAsync is called. I’ve tried a lot of different things but nothing seems to work.

System.Net.Http.HttpRequestException exception will running the UI Test on Physical Device..

$
0
0

I have created a simple Xamarin.Forms(Portable) project and included UI Test project in it. But when i am trying to run the test in physical device it giving me below mentioned exception.

Test Name:  AppLaunches
Test Outcome:   Failed
Result Message: 
SetUp : System.Net.Http.HttpRequestException : An error occurred while sending the request.
  ----> System.Net.WebException : The underlying connection was closed: The connection was closed unexpectedly.
Result StandardOutput:  Full log file: C:\Users\Admin\AppData\Local\Temp\uitest\log-2016-10-22_11-04-53-698.txt
Skipping IDE integration as important properties are configured. To force IDE integration, add .PreferIdeSettings() to ConfigureApp.
Android test running Xamarin.UITest version: 2.0.0.1534
Initializing Android app on device ZX1D63GCCL with installed app: co.veloxcore.UITestSample2
Signing apk with Xamarin keystore.
Skipping installation: Already installed.

Here is the link to my project: XamarinUITest

How to convert imagesource to base64

$
0
0
Hi all, i have an image source from a URL i need to convert it to base64 is there anyway to do that?

Draw Arabic Text using Skiasharp

$
0
0

Hi,

I'm trying to render Arabic text using Skiasharp, with no success. The characters are rendered disconnected and from left to right, please see the image below.

Any help would be appreciated, preferably without any special font or custom renderer...etc.

Thanks,

Entry - Only enter letters

$
0
0

Hi,

I'm building an app for Android and iOS. I have an Entry where the user may only type in letters. So not special characters, emojis, numbers and the space-bar. The only keyboard I can get now is this:

The best solution would be that the special characters, emojis, numbers and the space-bar should be removed/disabled from this keyboard, but I've read how difficult this is. So another solution would be that when the user presses these nothing should happen. I also don't know how to do that.

Can someone help me?

Regards, Ganesh

Apple SignIn Xamarin.Forms iOS. The Apple ID credential is revoked.

$
0
0

For some reason, I always have empty data

GZip Decompression/Deserialisation from Mobile application side

$
0
0

Hi,

I am working on Xamarin forms and My app consume WEB API which used GZIP to compress data.
How can I decompress this.
HttpClientHandler httpHandler = new HttpClientHandler()
{
AutomaticDecompression = System.Net.DecompressionMethods.GZip | System.Net.DecompressionMethods.Deflate
};

But this is not working. Please help me with the correct solution for this

UITest for Push To Talk button

$
0
0

I'm trying to write a UI test for a custom drawn button that can be in a pressed state or a released state (for push to talk)

IApp has a TouchAndHold method. However there is no way to set a hold duration. The Xamarin Docs also don't say how long the hold is for. My testing indicates that hold is only momentary.

There is also no TouchRelease (further indicating that TouchAndHold is temporary)

What I really need is way to do a touch down (then check that UI updates correctly to indicate we are transmitting) and then issue a touch release (and check the UI stop showing we are transmitting)

Is there anyway with UITest to do separate touch down and touch up actions?


New file type of xamarin forms app

$
0
0

I am developing an app which needs data to be shared with other users.
I need to create new file type extension like pti or sbd. I want android/ios to know that my app can open these files.
For sharing I am using Xamarin Essentials Share.RequestAsync.

How do I reference one XAML MergedDictionary from another?

$
0
0

I am struggling with XAML Merged Dictionaries. Is it possible to get something like the following working?

File Colours.xaml contains this:

<?xml version="1.0" encoding="utf-8" ?>
<?xaml-comp compile="true" ?>
<ResourceDictionary xmlns="http://xamarin.com/schemas/2014/forms"
                    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">

    <Color x:Key="WarningTextColour">#FF0000</Color>

</ResourceDictionary>

Another file Text.xaml contains something like this:

<?xml version="1.0" encoding="utf-8" ?>
<?xaml-comp compile="true" ?>
<ResourceDictionary xmlns="http://xamarin.com/schemas/2014/forms"
                    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
    <Style x:Key="WarningTextStyle" TargetType="Label">
        <Setter Property="TextColor" Value="{StaticResource WarningTextColour}"/>
        <Setter Property="FontSize" Value="Large"/>
    </Style>
</ResourceDictionary>

Then somewhere like my main App.xaml file, I bring them together like this:

<Application xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="myProject.Forms.App">

    <Application.Resources>
        <ResourceDictionary Source="Styles/Colours.xaml"/>
        <ResourceDictionary Source="Styles/Text.xaml"/>
    </Application.Resources>

</Application>

I've read the guides and tried various combinations of syntax, trying both the old and the new ways, but I can't find a way to do this. I am beginning to wonder if I am maybe approaching this completely the wrong way.

Even with all my XAML set to compile, the project builds okay (which is disappointing if I have something wrong), but the MainPage.xaml that tries to use the WarningTextStyle gives an exception.

Any help or advice would be very much appreciated.

Kind wishes ~ Patrick

Saving xml files on extern USB-Stick

$
0
0

Hey, this is my first thread in this forum. My history: I just began developing in Xamarin forms. I´ve got a problem: I have a xml file in the following folderpath on my tablet storaged (var backingFile4 = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "test.xml");.
I have connected the tablet to a USB-Stick and I wanna save the file from my tablet to a path on the stick. Would you please post a little snippet for my understanding?
Please help... LG Andre

Master Detail Default Example

$
0
0

Hey guys, I want to know why in the new project with the master detail template there is a delay for android in the MainPage.xaml.cs and some especific code for iOS in the MainPage.xaml. I'm using the most updated version of visual studio 2019.

Here is the portion of MainPage.xaml:

<MasterDetailPage.Detail>
    <NavigationPage>
        <NavigationPage.Icon>
            <OnPlatform x:TypeArguments="FileImageSource">
                <On Platform="iOS" Value="tab_feed.png"/>
            </OnPlatform>
        </NavigationPage.Icon>
        <x:Arguments>
            <views:ItemsPage />
        </x:Arguments>
    </NavigationPage>
</MasterDetailPage.Detail>

Here is the portion of MainPage.xaml.cs:

public async Task NavigateFromMenu(int id)
{
    if (!MenuPages.ContainsKey(id))
    {
        switch (id)
        {
            case (int)MenuItemType.Browse:
                MenuPages.Add(id, new NavigationPage(new ItemsPage()));
                break;
            case (int)MenuItemType.About:
                MenuPages.Add(id, new NavigationPage(new AboutPage()));
                break;
        }
    }

    var newPage = MenuPages[id];

    if (newPage != null && Detail != newPage)
    {
        Detail = newPage;

        if (Device.RuntimePlatform == Device.Android)
            await Task.Delay(100);

        IsPresented = false;
    }
}

NavigationBar.TitleView does not hide menu icon in UWP.

$
0
0

This is my NavBar title view:

<NavigationPage.TitleView>
        <StackLayout Margin="0" Padding="6,0,6,0" BackgroundColor="Yellow"
                     Orientation="Horizontal">
            <Button VerticalOptions="Center" ImageSource="backArrow_icon.png"
                    HorizontalOptions="Start"
                    HeightRequest="30" MinimumHeightRequest="30"
                    WidthRequest="30" MinimumWidthRequest="30"/>
            <Label VerticalOptions="Center"
                   HorizontalOptions="StartAndExpand"
                   Text="{x:Static resources:AppResources.Share}"/>
            <Button VerticalOptions="Center" ImageSource="Check_Icon.png"
                    HorizontalOptions="Start"
                    HeightRequest="30" MinimumHeightRequest="30"
                    WidthRequest="30" MinimumWidthRequest="30"/>
        </StackLayout>
    </NavigationPage.TitleView>

How do I make the menu icon marked in red, invisible? or get rid of it?

Viewing all 89864 articles
Browse latest View live


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