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

HorizontalListView inside custom ViewCell of ListView

$
0
0

Hello

My app contains ListView that has custom rendered ViewCells. Each of ViewCell contains HorizontalScrollView with simple content.
When I scroll HorizontalScrollView and immediately scroll ListView vertically, then magic happens.

Newly rendered HorizontalScrollView has scroll position X of last destroyed HorizontalScrollView..

How to prevent this? Is this bug? Why is this happening?

I attach simple project with that problem.
Steps to reproduce: Start Android Project -> Scroll first row horizontally -> scroll listView vertically -> Bug! Newly created row has scroll position X of the first row.


MasterDetailPage - Bar at the top of the Detail's Page

$
0
0

Hi,
In my project, i made a Master Detail Page with a Detail page, but on this page, i have a bar a the top and i don't know why.
Does anyone already had this problem ?

Thanks !

How to use ScrollToAsync at the building or appearing of a content page?

$
0
0

Hello,

I built a grid with a lot of rows.

I added a scrollview over the grid.

When I executed the ScrollToAsync method after the building of my grid: Nothing happens

I tried to execute it in the Appearing event method of Content page, in the Sizechanged event of my scrollview (with a condition on the Height property) : Nothing happens

I included a button in the content page (outside of the scrollview) and I added in the Clicked event with the ScrollToAsync method, it works !!

Somebody can help me ?

Thank you

Hint text not displaying on Android text entries

$
0
0

I'm new to xamarin, and have just created a new project. I'm wondering how I can get the floating hints/labels to appear above text fields when they are selected, as illustrated in the google material design documentation (see labels: https://material.io/guidelines/components/text-fields.html#text-fields-input)

I've created a custom renderer for my entry control, this all builds and works fine, but I'm not 100% certain of the properties of the control I need to set.

I found this article: https://blog.xamarin.com/add-beautiful-material-design-with-the-android-support-design-library/

But it seems to cover Xamarin.Android apps rather than Xamarin.Forms apps? unless I'm misunderstanding something fundamental here!

Thanks for your help!

How to focus the textbox inside the list view

$
0
0

Hi all,

I have a listview which contains a button and a textbox. When we click on button the text field should get focused.

But here iam getting error when try to access the button click event inside a list view in the code behind.

How can i implement this ?

Is there a way to handle opacity differently at some point?

$
0
0

I am using the skiasharp library to create an image editor in xamarin forms.

Is there a way to handle opacity differently at some part?

For example, you can divide the area of the background canvas, one of which looks like the original image and the other looks opaque. Is this possible?

ex

Sending email from app directly

$
0
0

Hi,

is it possible to send email directly from app without opening email client? I want user to type in text and just send it to predefined email address with predefined subject.

"Java.Lang.IllegalStateException: Activity has been destroyed" when using AdMob

$
0
0

I have done some tests of how to use AdMob in Xamarin.Forms and I got stuck on this.
Scenario:

  • A MasterDetailPage containing an empty master and a detail that is a new NavigationPage(myAdPage)
  • Start the application
  • Click on the (test)-ad and it will open a window
  • Click on the hardware back button twice and you get Java.Lang.IllegalStateException: Activity has been destroyed

A simple solution is attached.

Any clues of what to change to avoid this crash?


Did something change from 2.3.1.114 to 2.3.3.180 with regard to Android fonts?

$
0
0

I have just upgraded to 2.3.3.180, and started to get crashes everywhere on Android regarding Custom Fonts.

Specifically, in our CustomLabelRenderer base.OnElementChanged call, we are seeing an unhandled exception "Java.Lang.RuntimeException: Font asset not found {fontname}".

I have found that if I strip the font name right back to its basic name (i.e. fontawesome.ttf instead of \assets\fonts\fontawesome.ttf) then the crash goes away, but this means a huge refactoring going back through thousands of lines of XAML to amend every font (for Android only).

It seems that suddenly Xamarin are trying to load the font for us instead of having to have a custom renderer, but it doesnt like the path names.

I changed the font names on a few pages to see if this actually worked now, and while the error goes away, the font doesnt actually get used, so im not sure what is trying to be achieved here...

Anyone else come across this?

Remove gap between toolbar and tabs

$
0
0

I recently started exploring Xamarin.Forms again and I ran into an issue when using custom tabs and toolbar layout overrides. You can see the result below:
image

The following makes up the tabs.axml and the toolbar.axml under .\Resources\layout.

tabs.axml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.TabLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/sliding_tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:tabIndicatorColor="@android:color/white"
    app:tabGravity="center"
    app:tabMode="fixed"
    android:padding="0dp" />

toolbar.axml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:minHeight="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

MainActivity.cs:

FormsAppCompatActivity.TabLayoutResource = Resource.Layout.tabs;
FormsAppCompatActivity.ToolbarResource = Resource.Layout.toolbar;

base.OnCreate (bundle);

global::Xamarin.Forms.Forms.Init (this, bundle);

LoadApplication (new App ());

Does anyone have any suggestions? If I can't get this resolved quick, I'm going to have to go back to platform independent UI's.

I honestly do not know what is causing this.

XamlParseException Xamarin Forms

$
0
0

I got this error by trying to put an Method on a Button click Event
How Am I supposed to fix this? I saw many Thread About this telling me it's my Linker Options, but the linker option is "Ok", it was None by default and didn't worked.

Error

Here is My Project

Linker

XAML Home Page

Code Behind

XslCompiledTransform within PCL

$
0
0

Hello,

I'm trying to use XslCompiledTransform class to transform xml to html using an xsl stylesheet within my PCL project, but I keep getting "The type or namespace name 'XslCompiledTransform' could not be found (are you missing a using directive or an assembly reference?)" I have a "using System.Xml.Xsl;"
Am I missing something?

Thanks,

ViewCell.ContextActions is not working for Xamarin.iOS.

$
0
0

Hello Guys,

I am using ListView control for listing some records.
Also I have used "ViewCell.ContextActions" for delete list item.
This is working fine on Android, but for iOS it is not working.

Whenever I will call the ListView page, the application does nothing also it is not showing any exception.

<ListView x:Name="list" ItemSelected="OnSelection" ItemTapped="OnTap" IsPullToRefreshEnabled="true" Refreshing="OnRefresh">
        <ListView.ItemTemplate>
          <DataTemplate>
            <ViewCell>
              <ViewCell.ContextActions>
                <MenuItem Clicked="OnMore" Text="More" CommandParameter="{Binding .}" />
                <MenuItem Clicked="OnDelete" Text="Delete" IsDestructive="true" CommandParameter="{Binding .}" />
              </ViewCell.ContextActions>
              <StackLayout Padding="15,0">
                <Label Text="{Binding .}" />
              </StackLayout>
            </ViewCell>
          </DataTemplate>
        </ListView.ItemTemplate>
      </ListView>

Master Detail Page - Status Bar Problem on Android

$
0
0

I have a problem with the master detail page on Android. The drawer hides even the status bar. You can see only the icons...
I would like to have a semi transparent status bar. I have exactly the same code as in the docs.

How it looks like

What I would like to achieve

Xamarin.forms.maps not visible in UWP

$
0
0

I am new to Xamarin.forms and need to use maps for UWP platform. I have installed Xamarin.Forms.Maps nuget package in my PCL. And have called the init function in the App.xaml.cs of UWP section as follows:

Xamarin.Forms.Forms.Init(e); Xamarin.FormsMaps.Init("TokenKey");

However, the maps is not visible on deploying. I have added some pins as well and what I see is some blue screen, with the pins. I have tried lot of options, but have found no luck yet. Below is the code snippet for calling maps:

Map map = new Map(MapSpan.FromCenterAndRadius(new Position(51.5074, 0.1278), Distance.FromMiles(10)));
        map.MapType = Xamarin.Forms.Maps.MapType.Hybrid;
        map.HeightRequest = 700;
        map.WidthRequest = 725;
        map.IsShowingUser = true;
        var position1 = new Position(51.5033, 0.1195);
        var pin1 = new Pin { Type = PinType.Place, Position = position1, Label = "label1", Address = "address1" };
        map.Pins.Add(pin1);
        var position2 = new Position(51.5014, 0.1419);
        var pin2 = new Pin { Type = PinType.Place, Position = position2, Label = "label1", Address = "address1" };
        map.Pins.Add(pin2);
        this.mapGrid.Children.Add(map);

Am I doing anything wrong ? Or is there any missing reference that I should be adding to make this work ? Please help me out. Attached a snapshot of the map view for your reference.
P.S- The same solution loads a map on my colleague's machine, but doesn't work on others' machines.

Regards, Swati


My service and board cast stop working if the apps killed

$
0
0

thank you on advance
I have Issue and I hope u can help me
I m trying to design a service on android to check the httpclient every 10s and notify the the user. the application working find until I kill the apps.

can anyone help me

this my activity :

`using System;
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;

namespace Lawyer.Droid
{
[Activity(Label = "Lawyer.Droid",LaunchMode=Android.Content.PM.LaunchMode.SingleTop, Icon = "@drawable/icon", Theme = "@style/MyTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;

        base.OnCreate(bundle);

        global::Xamarin.Forms.Forms.Init(this, bundle);

        LoadApplication(new App());


        StartService(new Intent(this, typeof(myservice)));



    }
}

}
`

this is my service

using System.Threading;
using System.Threading.Tasks;
using Android.App;
using Android.Content;
using Android.Widget;
namespace Lawyer.Droid
{
[Service(Enabled = true,Exported = true, Name = "lawyer.Droid.myservice")]
class myservice : IntentService
{
public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
{

        new Task(() =>
            {
                while (true)
                {
                     Intent intents = new Intent();
                     intents.SetAction("com.alr.text");
                        //intents.PutExtra("MyData", "Data from service");
                     SendBroadcast(intents);
                    Toast.MakeText(this, "sufyan", ToastLength.Long);
                    Thread.Sleep(10000);
                }

            }).Start();


        return StartCommandResult.Sticky ;
    }

    protected override void OnHandleIntent(Intent intent)
    {

    }

}

this is my board cast :

using System.Collections.Generic;
using System.Net.Http;
using Android.App;
using Android.Content;

using Newtonsoft.Json;

namespace Lawyer.Droid
{
public class Myreciver
{

    //public Myreciver()
    [BroadcastReceiver(Exported = true, Label = "SMS Receiver")]

    [IntentFilter(new string[] {"com.alr.text"})]
    [IntentFilter(new[] { Android.Content.Intent.ActionBootCompleted })]


    //[IntentFilter(new string[] {  "Android.Content.Intent.ActionBootCompleted" })]
    public class SMSReceiver : Android.Content.BroadcastReceiver
    {

        string content1;
        public int d1;
        public override void OnReceive(Context context, Intent intent)
        {

            // Log.Info(Tag, "Intent received: " + intent.Action);
            // read the SendBroadcast data
            if (intent.Action == "com.alr.text")
            {
                // check the data count is null
                if (Lawyer.EmptyClass.Data_count_1 == "")
                {
                    Lawyer.EmptyClass.Data_count_1 = "0";
                }
                // call the php code
                sendtophp();
                if (d1 <= System.Convert.ToInt32(Lawyer.EmptyClass.Data_count_1))
                {

                }
                else {


                    // Start main Activity (you can replace with whatever Activity you want here)
                    var intent1 = context.PackageManager.GetLaunchIntentForPackage(context.PackageName);
                    intent1.AddFlags(ActivityFlags.ClearTop);

                    var pendingIntent = PendingIntent.GetActivity(context, 0, intent, PendingIntentFlags.UpdateCurrent);

                    var context1 = Android.App.Application.Context;
                    var builder = new Android.App.Notification.Builder(context1)
                        .SetSmallIcon(Resource.Drawable.icon)
                        .SetContentTitle("My application")
                        .SetDefaults(NotificationDefaults.Sound)
                        .SetContentText(Lawyer.EmptyClass.Data_count_1)
                        .SetOngoing(true);
                    var not = builder.Build();
                    NotificationManager notManager = (NotificationManager)context.GetSystemService(Context.NotificationService);
                    notManager.Notify(1, not);
                    Lawyer.EmptyClass.Data_count_1 = d1.ToString();


                }
            }
            //read incomming sms

        }
        public async void sendtophp()
        {


            var client = new HttpClient();
            try
            {
                var response = await client.GetAsync("url");
                if (response.IsSuccessStatusCode)
                    content1 = await response.Content.ReadAsStringAsync();
                var result = JsonConvert.DeserializeObject<List<MSG>>(response.Content.ReadAsStringAsync().Result);

                d1 = result.Count;
            }
            catch (System.Exception e)
            {

            }
        }



        public class MSG
        {
            public string date { get; set; }
            public string text { get; set; }
            public string text1 { get; set; }
            public string user { get; set; }
            public string password { get; set; }
        }
    }

}

}

Xamarin.Forms Splashscreen in Android

$
0
0

Hi, In Forms how to add SplashScreen to Android appliaction? Thanks in advance.

Formatting Month and Date for Localization in Xamarin.Forms

$
0
0

I have the following code:

<Label Text="{Binding startTime, StringFormat='{0:MMM d, yyyy }'}" which renders June 18, 2017

I'd like to create a string that renders 18 June 2017 when the culture is not US.

Any ideas on how to do that?

Thanks.

zxing scanner

$
0
0

I am Use Zxing for scanner the QR the Problem is Why the Button Text and Top Text is not show

Out of memory on Android with listview having an image in it

$
0
0

I have discovered that Android can run out of memory quite quickly with a listview that has an image in its itemtemplate, if that image has a large width and height.

The file size of the image does not matter, just the width/height of it. My image is a 1280x337, 3KB png, and with just five to ten items in my listview, it will crash when you scroll it.

    public OtherPage ()
    {
        Title = "Other Page";

        BackgroundColor = Color.White;

        var settings = new ListView ();
        settings.RowHeight = 120;

        List<string> items = new List<string> ();
        for (int i = 0; i < 8; i++) {
            items.Add ("Item " + i);
        }
        settings.ItemsSource = items;

        settings.ItemTemplate = new DataTemplate (() => {

            Image gradientOverlay = new Image()
            {
                Source = "colorgradient.png",
                Aspect = Aspect.Fill
            };

            Grid screenGrid = new Grid () {
                VerticalOptions = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.StartAndExpand,
                RowDefinitions =
                {
                    new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }
                },
                ColumnDefinitions =
                {
                    new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }
                }
                };

            screenGrid.Children.Add(gradientOverlay, 0, 0);

            return new ViewCell {
                View = screenGrid,
            };
        });

        Content = settings;

    }

Bug filed here: https://bugzilla.xamarin.com/show_bug.cgi?id=22510

Note: image is attached below but image is mostly white so is hard to see.

Viewing all 91519 articles
Browse latest View live