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

Sqlite in PCL and Model classes

$
0
0

Hi :) , I'm a newbie in Xamarin Forms and a Student for Software Programming I'm doing an App that needs an Sqlite but what I have seen is people using SQLite.Net-PCL and always using the "Model classes" like:

namespace DatabaseDemo
{
    public class Model
    {
        [PrimaryKey, AutoIncrement]
        public int ID { get; set; }
        public string Name { get; set; }
    }
}

It's totally necessary to do that? I can't do a CREATE TABLE or something different? Exists a way to do this easiest if I need a lot of tables?

PD: sorry if it's a stupid question :/


Am I missing something re. Title properties when using MasterDetailPage?

$
0
0

When I started working with Xamarin.Forms, I found that MasterDetailPage did not do what I wanted and contained multiple bugs. I therefore wrote something to replace MasterDetailPage in my own code, to get the precise result I wanted.

I thought I'd take a peek at the current state of MasterDetailPage (using XF 2.4.0.38779) to see how it has changed since then.

At https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/navigation/master-detail-page/
it says:

"The MasterDetailPage.Master property is set to a ContentPage instance. The MasterDetailPage.Detail property is set to a NavigationPage containing a ContentPage instance."

and:

"The MasterDetailPage.Master page must have its Title property set, or an exception will occur."

Following those two guides, and using MasterBehavior.Split, I find that the Title set on the Master page is not displayed. It seems odd that setting it is required if it's not then displayed. Am I missing something?

Also, on that same page, it says:

"MasterDetailPage is designed to be a root page, and using it as a child page in other page types could result in unexpected and inconsistent behavior. In addition, it's recommended that the master page of a MasterDetailPage should always be a ContentPage instance, and that the detail page should only be populated with TabbedPage, NavigationPage, and ContentPage instances. This will help to ensure a consistent user experience across all platforms."

I find that if I use MasterDetailPage as a child page, on UWP the Detail page's Title is displayed twice. Must be one of those "unexpected and inconsistent behaviors". Seems odd though - if it was going to do something like that, I would have expected that to happen on Android and UWP as well. Makes me wonder if UWP is not kept quite up to date with Android and UWP when it comes to MasterDetailPage...

The good thing is that this latest dabble with MasterDetailPage makes me think creating my own replacement was the right thing to do, even if it took a fair amount of work.

For info, the hacky code I used whilst dabbling with this today is as follows:

using Xamarin.Forms;

namespace ViewsUsingXamarinForms
{
    public class MyAppMasterDetailPage : MasterDetailPage
    {
        public MyAppMasterDetailPage()
        {
            Master = new ContentPage
            {
                BackgroundColor = Color.Yellow,
                Content = new StackLayout
                {
                    VerticalOptions = LayoutOptions.Center,
                    Children =
                    {
                        new Label
                        {
                            HorizontalTextAlignment = TextAlignment.Center,
                            FontSize = 30,
                            BackgroundColor = Color.Blue,
                            TextColor = Color.Aqua,
                            Text = "Master"
                        }
                    }
                },
                Title = "Master ContentPage title"
            };

            Detail = new NavigationPage(new ContentPage
            {
                BackgroundColor = Color.Yellow,
                Content = new StackLayout
                {
                    VerticalOptions = LayoutOptions.Center,
                    Children =
                    {
                        new Label
                        {
                            HorizontalTextAlignment = TextAlignment.Center,
                            FontSize = 30,
                            BackgroundColor = Color.Green,
                            TextColor = Color.Lime,
                            Text = "Detail"
                        }
                    }
                },
                Title = "Detail ContentPage title"
            })
            {
                Title = "Detail NavigationPage title"
            };

            Title = "MasterDetailPage title";
            MasterBehavior = MasterBehavior.Split;
        }

    } // public class MyAppMasterDetailPage : MasterDetailPage

} // namespace ViewsUsingXamarinForms

// eof

Notification cross platform: How to show Notification?

$
0
0

Hi community,
I realized an app with xamarin forms, and I try to create a Notification for incoming message. I need to know hot to realize that.
If I use different platform tecnique, I have problem with Android /Intent --> I set an Intent with data and set a Notification Content Intent to Main page. But in main page I cant call
var string = Intent.GetStringExtras()
Because say me that I can't use it because "I need a object reference to use GetStringExtras

Is there anyway to resolve problem or use a SINGULAR notification code for 3 platform?

CarouselPage binding

$
0
0

I haven't used the CarouselPage before and I cannot get the binding for the children pages to work. I have something like this:

`    <?xml version="1.0" encoding="utf-8" ?>
<CarouselPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:JaaTyrePal;assembly=JaaTyrePal"
             xmlns:iconize="clr-namespace:FormsPlugin.Iconize;assembly=FormsPlugin.Iconize"
             x:Class="JaaTyrePal.HomePage"
             NavigationPage.HasNavigationBar="false">
    <ContentPage x:Name="Page1" BackgroundColor="Black"  >
        <Label Grid.Row="0" Grid.Column="1" Text="{Binding Temp}" Style="{StaticResource GaugeLabel}"/>

    </ContentPage>
    <ContentPage x:Name="Page2" BackgroundColor="Black" Title="Right Tyres">
         <Label Grid.Row="0" Grid.Column="1" Text="{Binding TempB}" Style="{StaticResource GaugeLabel}"/>
    </ContentPage>
</CarouselPage>`

And my simple ViewModel:
`

            public HomePageModel(MasterParameterContainer masterContainer)
            {
                Temp = 2.3;
            }

            double _temp;
            double Temp
            {
                get
                {
                    return _temp;
                }
                set
                {
                    _temp = value;
                    RaisePropertyChanged();
                }

`

I cant get the binding to work for ContentPages, I even tried the following in the code behind:

`protected override void OnBindingContextChanged()
        {
            Page1.BindingContext = BindingContext;
            Page2.BindingContext = BindingContext;
            base.OnBindingContextChanged(); 
        }`

What am I doing wrong here?

How to cast video from phone to TV in xamarin forms?

$
0
0

Hi everybody!
I learning my self with simple Move app. So How to cast video from phone to TV in xamarin forms?
Thank you!

I want to take backup and restore of SQLite Database file using xamarin Azure SDK for My Xamarin App

$
0
0

I am using xamarin Azure SDK to download and manage the local database for my Xamarin . Forms App.

We are facing downloading time issues because we have a lot of data.
so I am thinking of taking backup once of the SQLite File from one device and use it to restore on different devices as restoring the same SQLite File.

Planned to use Azure Blob storage to store backup of SQLite files and for different device planning to download that blob of SQLite file and thinking of restore it on different devices.

Any Help will be appreciated.

Thanks :)

Acr Userdialoges not working

$
0
0

Hi,
I have a strange problem.
In my login page, I am using Acr.UserDialogs. If I give the correct credentials userdialoges not work, but with wrong credentials, userdialoges working fine.
I am confused with this? Any idea :)
Thanks in advance :)

Frame doesn't have shadow

$
0
0

I'm using Frame in my page I set the hasShadow prop to true, still nothing shows


Loop through the dynamically created views in Xamarin.form

$
0
0

I just create some of the dynamic views in xamarin.fom . now i want to iterate through that views to identify the view type .how can i make it possible in xamarin.form
any help be appreciable ; please help me i am stuck.

Custom ViewCell with bindable custom object

$
0
0

I'm here with a question that is bothering me for the last couple of days and I was unable to find a clear explanation for. What I want to accomplish: Create a custom ViewCell of which BindableProperty is a complex object. A this moment I receive a null value in my BindableProperty. Any tip is of great help.

ViewCell's code behind:

`
public partial class ValidatableText : ViewCell
{
public static readonly BindableProperty BindedObjectProperty =
BindableProperty.Create(
nameof(ObjectToValidate),
typeof(ValidatableObject),
typeof(ValidatableText),
default(ValidatableObject));

    public ValidatableObject<string> ObjectToValidate
    {
        get
        {
            var value = GetValue(BindedObjectProperty);
            var result = value as ValidatableObject<string>;
            return result;
        }
        set
        {
            SetValue(BindedObjectProperty, value);
            OnPropertyChanged(nameof(ObjectToValidate));
        }
    }

    protected override void OnPropertyChanged([CallerMemberName]string propertyName = null)
    {
        if (!string.IsNullOrWhiteSpace(propertyName) && propertyName == BindedObjectProperty.PropertyName)
        {
            base.OnPropertyChanged(propertyName);
        }
    }

    public ICommand ValidateInput
    {
        get
        {
            return new Command(() =>
            {
                this.ObjectToValidate.Validate();
            });
        }
    }

    public ValidatableText()
    {
        InitializeComponent();
        BindingContext = this;
    }
}`

ViewCell's Calling:

<ContentPage.Content> <TableView Intent="Form" HasUnevenRows="True"> <TableRoot > <TableSection Title="Creditentials"> <cells:ValidatableText ObjectToValidate="{Binding Email}"> </cells:ValidatableText> </TableSection> </TableRoot> </TableView> </ContentPage.Content>

Caller's ViewModel:

`public ValidatableObject Email
{
get => _email;
set
{
_email = value;
this.OnPropertyChanged();
}
}

public RegisterUserViewModel()
{
this.Email = new ValidatableObject();
this.Email.Validations.Add(new EmailRule(){ValidationMessage = "Invalid email format"});
}

`

Kind regards!

GradientBoxView Custom renderer

$
0
0

I'm trying to recreate the gradient background effect from here:
https://forums.xamarin.com/discussion/22440/gradient-as-background-color

But instead of using it as page background I want to use it in a boxView, the problem is that IOS renders the colors into lighter versions, as if it has opacity values under 1 (or similar...)

For the common component I'm extending the boxview class adding it a two Xamarin.Forms.Color properties (StartColor and EndColor):

public class GradientBoxView : BoxView
{
    public Xamarin.Forms.Color StartColor { get; set; }
    public Xamarin.Forms.Color EndColor { get; set; }
}

The custom renderer class for IOS is this:

public class GradientBoxViewRenderer : BoxRenderer 
{
    public override void Draw (CGRect rect)
    {
        base.Draw (rect);
        this.Element.Opacity = 1;
        GradientBoxView box = (GradientBoxView)this.Element;

        CGColor startColor = box.StartColor.ToCGColor();//box.StartColor.AddLuminosity(1).MultiplyAlpha(2).ToCGColor();//
        CGColor endColor = box.EndColor.ToCGColor();//box.EndColor.AddLuminosity(1).MultiplyAlpha(2).ToCGColor();//

        var gradientLayer = new CAGradientLayer();
        //gradientLayer.Opaque = true;
        gradientLayer.Frame = rect;
        gradientLayer.Colors = new CGColor[] { startColor, endColor };
        //NativeView.Opaque = true;
        NativeView.Layer.InsertSublayer (gradientLayer, 0);
    }
}

Searching in the forum I did find someone having a similar issue with IOS topBar colors and the solution was setting "Opaque" to true and "Translucent" to false, but BoxView doesn't seems to have a Translucent property to play with and the "Opaque" one does nothing (at least I cant tell a difference by commenting/uncommenting the lines of my renderer where I play with it...)

Anyone here with the same issue or with any solution?

Dismiss AlarmClock

$
0
0

Hello I have a problem in Xamarin Forms (Visual Studio 2017) on Android.
I use AlacmClock Intent to create an alarm like this:
private void SetAlarmClock(int minutes, string message)
{
try
{
string ringtoneUri = App.UserSettings.GetSettings("RingtoneUri");
DateTime alarmTime = DateTime.Now;
alarmTime = alarmTime.AddMinutes(minutes);
Intent intent = new Intent(AlarmClock.ActionSetAlarm);
intent.PutExtra(AlarmClock.ExtraHour, alarmTime.Hour);
intent.PutExtra(AlarmClock.ExtraMinutes, alarmTime.Minute);
intent.PutExtra(AlarmClock.ExtraMessage, message);
intent.PutExtra(AlarmClock.ExtraSkipUi, true);

            if (!string.IsNullOrEmpty(ringtoneUri))
                intent.PutExtra(AlarmClock.ExtraRingtone, ringtoneUri);
            context.StartActivity(intent);
        }
        catch (Exception ex)
        {
            App.UserSettings.WriteProtocol("SetAlarmClock Exception: " + ex.Message);
        }
    }

But I have also method for dismiss this alarm but it don't work:
private void DismissAlarmClock(string message)
{
try
{
Intent intent = new Intent(AlarmClock.ActionDismissAlarm); // This Intent can be used only for API 23 and higher (Android 6.0)
intent.PutExtra(AlarmClock.ExtraAlarmSearchMode, AlarmClock.AlarmSearchModeLabel);
intent.PutExtra(AlarmClock.ExtraMessage, message);
intent.PutExtra(AlarmClock.ExtraSkipUi, true);
context.StartActivity(intent);
}
catch (Android.Content.ActivityNotFoundException)
{
App.UserSettings.WriteProtocol("DismissAlarmClock AlarmClock.ActionDismissAlarm is not supported on Android 5.1 and lower!");
}
catch (Exception ex)
{
App.UserSettings.WriteProtocol("DismissAlarmClock Exception: " + ex.Message);
}
}

Problem 1: it dismisses the alarm not always
Problem 2: Nevertheless I use intent.PutExtra(AlarmClock.ExtraSkipUi, true); it opens always Alarm/Watches App on Android.

I have seen some examples on internet with AlarmManager and PendingIntent but this also don't works in my App.
Thanks.

Is it possible to implement iOS App Extensions in a Forms app?

DidReceiveRemoteNotification, ReceivedRemoteNotification are not being called while using FCM

$
0
0

Hi everyone, I'm trying to impalement push notifications in Xamarin forms using this plugin, Plugin.FirebasePushNotification
im receiving the notifications but after clicking on notifications, DidReceiveRemoteNotification, ReceivedRemoteNotification are not being called. how can I get notifications info in app ?

Here is the code

        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init();

            LoadApplication(new App());

            FirebasePushNotificationManager.Initialize(options, true);


            return base.FinishedLaunching(app, options);
        }

        public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
        {
#if DEBUG
            FirebasePushNotificationManager.DidRegisterRemoteNotifications(deviceToken, FirebaseTokenType.Sandbox);
#endif
#if RELEASE
                    FirebasePushNotificationManager.DidRegisterRemoteNotifications(deviceToken,FirebaseTokenType.Production);
#endif


            Console.WriteLine("deviceToken " + deviceToken);

        }

        public override void FailedToRegisterForRemoteNotifications(UIApplication application, NSError error)
        {
            Console.WriteLine("error " + error);

            FirebasePushNotificationManager.RemoteNotificationRegistrationFailed(error);

        }
        // To receive notifications in foregroung on iOS 9 and below.
        // To receive notifications in background in any iOS version
        public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
        {

            Console.WriteLine("DidReceiveRemoteNotification calling ");

            System.Console.WriteLine("Hello");

            FirebasePushNotificationManager.DidReceiveMessage(userInfo);
            // Do your magic to handle the notification data
            System.Console.WriteLine(userInfo);
        }


 public override void ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo)
        {

            Console.WriteLine("ReceivedRemoteNotification calling ");

            System.Console.WriteLine("Hello");

            FirebasePushNotificationManager.DidReceiveMessage(userInfo);
            // Do your magic to handle the notification data
            System.Console.WriteLine(userInfo);
        }

List view Item inside a box

$
0
0

I need to place list view items inside a box...
that means items placed inside a border...I tried with frame...It takes more space between the items and border...Any other idea to implement this
Thanks in Advance


How do I upload PDF/Docs in Xamarin form?

$
0
0

How do I upload PDF/Docs in Xamarin form? I am able to select and upload Image Files thought using MediaPicker though.

xam.Plugin.GeoLocator does not work

$
0
0

hi, I added xam.Plugin.GeoLocator inorder to get gps coordinates. But in Droid project I keep getting following error.

"java.lang.IllegalArgumentException: already added : Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat; Medarbeideren.Droid".
Did many solutions suggested. reinstalling nuget packages.change target API levels,etc. But the error is still the same. Any solutions for this?

UI Design

$
0
0

Hi guys,

Could you please suggest nice plugins for UI, or links on how to design my application...

The problem that I have, most of UI x stuff are for sale and they are pricey, more especially for us in Africa

How to display the data in table format.

$
0
0

I want to display the data in table structure like shown in attachment. I want Table Header as constant and the data will scroll.

Thanks..

iOS11 large titles in XAML

$
0
0

In reference to this post on the Xamarin blog: https://blog.xamarin.com/making-ios-11-even-easier-xamarin-forms/

I have set up what I think should be a proper ContentPage to use safe areas and large titles on NavigationPages in XAML (not exactly the topic of the post but I think I have the right idea).

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MyApp.Pages.MyPage" Title="Summary"
             xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core" 
             ios:NavigationPage.PrefersLargeTitles="true"
             ios:Page.UseSafeArea="true">

The page is invoked in C# like so:

Application.Current.MainPage = new NavigationPage(new SummaryPage());

The safe area works great, but the large titles don't display. Can you tell what I'm missing? I've read I should be able to do everything as a content page that I would do as a Navigation page, unless I'm misunderstanding: https://forums.xamarin.com/discussion/17704/navigationpage-in-xaml

Viewing all 58056 articles
Browse latest View live


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