Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all 204402 articles
Browse latest View live

Navigation Problem : Push and Pop 2x Problem

$
0
0

Hello All,

I have a Xamarin.Forms application where the main page is a MasterDetail.
After clicking on a Button , I set Detail Property : this.Detail = new NavigationPage(new Page1());
Page1 is shown.
In this Page1 I open en new Page (pagePopup) :

ChoicePage pagePopup = new ChoicePage ();
await Navigation.PushAsync(pagePopup );

Now When I go Back and open the ChoicePage again with the same code, the application is crashing.
"Unhadled Exception : Your app has entered a break state, but there is no code to show because all threads were executing external code (typically system or framework code)."

What is the reason ?

Regards,
Gert


GestureRecognizer is not working on android using Xamarin.forms

$
0
0

public void EnableSubmitButton(){
LeftMenuItem.IsEnabled = true;
TapGestureRecognizer OnLeftMenuItemClicked = new TapGestureRecognizer ((s,e) => {
OnSubmitClicked (s,e);
});
LeftMenuItem.GestureRecognizers.Add (OnLeftMenuItemClicked);
}

This is the code which is used to add gesture recognizer into the Image. It's working on iOS perfectly. But In android OnLeftMenuItemClicKed is not triggered.

Thanks in Advance.

BitmapFactory.decodeFile() returning null when i try to get image

$
0
0

When I am calling this function there is no image in _bitmap

          private void _btnResimYolu_Click(object sender, System.EventArgs e)
                        {
                            var imageIntent = new Intent();
                            imageIntent.SetType("image/*");
                            imageIntent.SetAction(Intent.ActionGetContent);
                            StartActivityForResult(
                                Intent.CreateChooser(imageIntent, "Resim Seç"), 0);
                        }

        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
                {
                    base.OnActivityResult(requestCode, resultCode, data);

                    if (resultCode == Result.Ok)
                    {
                        var imageView =
                            FindViewById<ImageView>(Resource.Id.img1);
                        imageView.SetImageURI(data.Data);
                        _imageTest.Text = data.DataString;
                    }
    private void _gonder_Click(object sender, System.EventArgs e)
        {
                            string uriString = _imageTest.Text;
                            _bitmap = BitmapFactory.DecodeFile(uriString);
                            MemoryStream stream = new MemoryStream();
                            _bitmap.Compress(Bitmap.CompressFormat.Jpeg, 100, stream);
                            byte[] ba = stream.ToArray();
                            string bal = Base64.EncodeToString(ba, Base64.Default);
}

Service stops after 24 hours - snoze mode?

$
0
0

Hello guys,

I'm currently working on a project which receives Messages over Bluetooth from an Arduino. This app will only be installed on one device running API 17.
I'm using the Smartphone only for receiving data over bluetooth, modifing the data and pushing data to an REST API using a mobile data connection.

Since the phone will always be connected to a charger i dont give a shit about battery usage, i only have one priority: Sending data to the web-API continously for multiple weeks without anyone touching the phone. (so there's no user who presses the power button)

Problem is: After 24 hours, my Web-API doesn't receive data from the phone anymore. Seems like the phone goes into dooze mode or something like that.
To prevent dooze mode i already run the code from a Foreground-Service (because i read that foreground-services have higher priority than background-services and i don't care about the type of service). I have a "public override void OnTaskRemoved(Intent rootIntent)"-Method which restarts the service to ensure that it never stops.
I'm also setting an alarmmanager for every start of the service like this:

public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
{
var alarmManager = ((AlarmManager)ApplicationContext.GetSystemService(Context.AlarmService));
var restartService = new Intent(this, typeof(BluetoothService));
var BluetoothIntent = PendingIntent.GetService(ApplicationContext, 10, restartService, PendingIntentFlags.UpdateCurrent);
// -> restart service every 2 hours
var triggerAfterMillis = Java.Lang.JavaSystem.CurrentTimeMillis() + 1000 * 60 * 120;
alarmManager.Set(AlarmType.RtcWakeup, triggerAfterMillis, BluetoothIntent);
}

So even if phone goes into dooze mode, the alarmmanager should trigger every 2 hours and restart my service. But still, everything stops working after 24 hours and the service doesn' restart.

Could anyone help me figure out why this is the case or does anyone know a solution to this problem?
Would really appreciate it, I'm stuck with this problem for quite a while now.

Build of samples fails with [resourcecache\0216097C3B1F97FDF394E6C737CAF651\res' does not exist]

$
0
0

I'm trying to get development with Xamarin up again but every sample that I download from the xamarin site fails when I try to build it.
And every time it is the same resourcecache\0216097C3B1F97FDF394E6C737CAF651\res that doesn't exist.
I see also other resourcecache folders with other ids and they have res folders, but resourcecache\0216097C3B1F97FDF394E6C737CAF651 doesn't.
It looks like the folder resourcecache\0216097C3B1F97FDF394E6C737CAF651 is created but after writing cache.stamp and classes.jar it doesn't write the rest.
When I create a new Android project, change nothing and then build it everything is okay.
I already checked the SDK Manager, downloaded all the latest packages and so on but all with no result.
I'm using Vistual Studio 2017 Professional on Win10 Pro.

Has anybody seen this before an managed to solve this?
I have to decide whether to build the new app in Xamarin (because we normally develop in C#) or in AndroidStudio and if I even don't get the official samples to work I'm very anxious to start in Xamarin.

Shared resources for separate android/iOS projects

$
0
0

I'm creating a Forms PCL project which will contain two Android apps (one for each company brand) and two iOS apps (one for each company brand), and one shared PCL.

I'm hoping that i will be able to store many of the shared resources (images, mostly, but possibly also text) in a shared project for each device. For the time being, there won't be any separate functionality between the two android and two iOS projects per brand, but that might happen down the road.

For example, I'd love this setup:
Root
- PCL Project (shared code, Forms, etc)
- Android.Shared (shared resources/localisations for the android apps)
- Android.Brand1 (custom resources (logos, colors, etc) for Brand1)
- Android.Brand2 (custom resources (logos, colors, etc) for Brand2)
- iOS.Shared (shared resources/localisations for the android apps)
- iOS.Brand1 (custom resources (logos, colors, etc) for Brand1)
- iOS.Brand2 (custom resources (logos, colors, etc) for Brand2)

I'm also wanting to be able to use the standard /drawable/dpi and /resources/@2x resource functionality within the four platform-specific apps as it already exists, but I'm unsure of how to set this up.

Any advice would be welcome, as I am fairly new to this whole process. Thanks.

Is there any way to scroll both up and down depending on where the element is located?

$
0
0

Tell me, please, is there any way, scroll up and down and up depending on where the element is located?
I am writing a test for android, using Xamarin.UITest
I use 1 general construction to search for an element.

Load more items without button click

$
0
0

Dears,

I am implementing load more items to listview without a button.

My code:

 public partial class DashBoardPage : ContentPage
  {
    ObservableCollection<string> Items;
    bool isLoading;

    public DashBoardPage()
    {
        InitializeComponent();

        Items = new ObservableCollection<string>();
        var listview = new ListView();

        listview.ItemsSource = Items;
        listview.ItemAppearing += (sender, e) =>
        {
            if (isLoading || Items.Count == 0)
                return;

            //hit bottom!
            if (e.Item.ToString() == Items[Items.Count - 1])
            {
                LoadItems();
            }
        };
        LoadItems();
    }

    public async void LoadItems()
    {
        isLoading = true;
        HttpClient client = new HttpClient();
        var response = await client.GetAsync("My Url");
        string tweetJson = await response.Content.ReadAsStringAsync();

        UserTweetResponse userTweetResponse = new UserTweetResponse();
        if (tweetJson != "")
        {
            userTweetResponse = JsonConvert.DeserializeObject<UserTweetResponse>(tweetJson.ToString());
        }
        ListView1.ItemsSource = userTweetResponse.userTweetsList;
        isLoading = false;
    }
}

I refer the following link and confused with the for loop inside LoadItems():
https://montemagno.com/load-more-items-at-end-of-listview-in/
for (int i = 0; i < 20; i++)
{
Items.Add (string.Format("Item {0}", Items.Count));
}
In my case I am using itemSource property to bind the response to list view.
How can I fix this?
Thanks in advance :)


I can't change navbar color!

$
0
0

Hi guys.

I'm handling a problem that should not be so hard to get out.

I can't change the navbar/toolbar colors. No matter what I do, it dont change!

It is always this white:

Things I've already done:

Reinstalled the xamarin forms, v7 appcompat library, custom styles, clean and rebuild project...

I can change text color but not the BarBackgroundColor. Not even accent color, apparently.

My styles.xaml:

<?xml version="1.0" encoding="utf-8" ?>
<resources>
  <style name="Theme.Splash" parent ="Theme.AppCompat.Light.NoActionBar">
   <item name="android:windowBackground">@drawable/splash</item>
   <item name="android:windowNoTitle">true</item>
   <item name="android:windowFullscreen">true</item>
 </style>


  <style name="MyTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:colorPrimary">#25aaed</item>
    <item name="android:colorPrimaryDark">#25aaed</item>
    <item name="android:colorAccent">#25aaed</item>
  </style>

</resources>

A piece of MainActivity:

[Activity(Label = "caronapp", Icon = "@drawable/icon", Theme = "@style/MyTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : FormsAppCompatActivity
{
    public static ICallbackManager CallbackManager = CallbackManagerFactory.Create();
    public static readonly string[] PERMISSIONS = new[] { "publish_actions" };

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        FacebookSdk.SdkInitialize(this.ApplicationContext);
        global::Xamarin.Forms.Forms.Init(this, bundle);
        LoadApplication(new App());
    }

Toolbar.axml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar

 xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?android:attr/actionBarSize"
   android:background="?android:attr/colorPrimary" />'

Where mainpage is created and called:

MainPage = new NavigationPage(new MainPage(token)) { BarBackgroundColor=Color.Lime, Tint=Color.Lime};

As you can see, I'm trying hard to change the color. Setting everything to #25aaaed or even Lime. I just want to change this boring white.

Am I missing something?

Thanks!

I can't build my project when i add GooglePlayServices !!!

$
0
0

Hello,

i need to add googleplayservices version 29.0.0.2 to my project but i am getting this error when i building my project, i don't understand what this error is about!
<br /> /Users/comenscene/Desktop/projects/epf/packages/Xamarin.GooglePlayServices.Basement.29.0.0.2/build/Xamarin.GooglePlayServices.Basement.targets(5,5): Error MSB4062: The "Xamarin.GooglePlayServices.Tasks.ProcessGoogleServicesJson" task could not be loaded from the assembly /Users/comenscene/Desktop/projects/epf/packages/Xamarin.GooglePlayServices.Basement.29.0.0.2/build/Xamarin.GooglePlayServices.Tasks.dll. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. (MSB4062) (epf.Droid)<br />
could anyone help me out on this?

Draw RadioButtons using Frame?

$
0
0

I'm creating a custom RadioButton control, currently I'm using those two glyphs :◉, ◯
but I prefer not using them as fonts may have unexpected behaviors regarding the environment.
so I need to draw them: I tried using Frame but can't approach the result I want:
this is one of many tries I made:

    <Frame Padding="3" CornerRadius="10"
                       WidthRequest="10" HeightRequest="10" BackgroundColor="Black"
                       VerticalOptions="Center" HorizontalOptions="Center">
                    <Frame Padding="5" CornerRadius="5"
                       WidthRequest="5" HeightRequest="5" BackgroundColor="White"
                       VerticalOptions="Center" HorizontalOptions="Center">
                    </Frame>
                </Frame>

None of them made the empty circle

App Rejection

$
0
0

Hi,

I've tried to submit an Xamarin.Forms app I've been working on to the iOS store today via the Application Loader, however I've had this message back which I don't understand, Any insight would be appreciated.

(File attached of image)

Package Summary

1 package(s) were not uploaded because they had problems:
    /var/folders/fs/8csfgjm10ljbmtz526yrhq080000gn/T/6610ABD3-67BA-47DF-BD10-F8C42DCA1499/1176937956.itmsp - Error Messages:
        description length:636214
        ERROR ITMS-90717: "Invalid App Store Icon. The App Store Icon in the asset catalog in 'SOLUTION' can't be transparent nor contain an alpha channel."

Thanks,
Sean

ListView desperately needs a SelectedItemBackgroundColor property

$
0
0

It's a very basic thing, nobody wants an ugly grey (or blue) bar to appear as the background when you select an item in a ListView. It looks terrible from a UI point of view. Everybody has been implementing their own workarounds for this (custom renderers etc) but it is getting out of hand.

The ViewCellRenderer custom renderer approach works fine with a ListView with the default caching strategy ListViewCachingStrategy.RetainElement but it does NOT work if you set it to ListViewCachingStrategy.RecycleElement or ListViewCachingStrategy.RecycleElementAndDataTemplate .

If you need a different caching strategy you have to go one step further and create a custom ListViewRenderer and then assign your own UITableViewDelegate based delegate, and from there you need to override the WillDisplay method in order to eventually be able to set the selected item's background color to something that matches your app's color scheme. And after all this you'll find there are problems with the fact that you're replacing the "default delegate". (note: conversely and ironically this ListViewRenderer approach seems to work ok with a ListView that has a non-default caching strategy set but it does NOT work with the default caching strategy - in the latter case it doesn't pick up the ItemSelected event anymore). The problem with overwriting the default delegate is described here: https://forums.xamarin.com/discussion/42863/setting-delegate-of-control-in-custom-renderer-results-in-lost-functionality

The problem and various workarounds that people have been trying is summarised here (but still there are some problems as mentioned in paragraph above):

In short this is madness that each developer must go through all this pain for such a simple thing.

To solve all this a simple SelectedItemBackgroundColor property should be added to the ListView class. It won't be difficult to add the required code (just some code in the custom renderers will do the trick). Then we won't have to worry about all these custom renders or about how to handle the overwritten default delegate.

Maps Ios position difference

$
0
0

Hi all,

I have follow this link
https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/custom-renderer/map/customized-pin/

But i have a problem on Ios on function "GetCustomPin" :

PinMotoAlarm GetCustomPin(IMKAnnotation annotation)
        {
            var nativelement = (CustomMap)this.Element;
            var position = new Position(annotation.Coordinate.Latitude, annotation.Coordinate.Longitude);
            foreach (var pin in nativelement.CustomPins)
            {
                if (pin.Position == position)
                {
                    return pin;
                }
            }
            return null;
        }

Position of annotation is never equal with my custon pin. It's normal ?

Thanks in advance for help.

How to create simple TabbedPageRenderer for iOS and Android in Xamarin Forms

$
0
0

Need Simple working Tabbedpage Renderer


MessageCenter.Unsubscribe *doesn't* unsubscribe - Anyone else see this?

$
0
0

Case

I have a ViewModel that lives for the lifespan of the app.
When a given feature is turned on, I subscribe to a given MessagingCenter message.
When the feature is turned off, I unsubscribe.
{repeat}
Seems simple enough.

Problem

Despite the unsubscribing the handler for the subscription is getting called once for every .Subscribe taking place. As if the .Unsubscribe isn't doing its job.

Test

In a fit of desperation I even tried to .Unsubscribe 10 times using both overloads of the method. If there is not subscription existing then no-harm-no-foul, right?

Yet the multiple handling of the single incoming message still happens. Anyone else run across this?

It seems related to, but not identical as, this thread... For one thing, I'm not disposing of either the View or the ViewModel - so there shouldn't be an orphaned subscription hanging out there. this is always the same instance of this in other words.
https://forums.xamarin.com/discussion/20420/messagingcenter-causing-problems-if-unsubscribing-within-message-handler
I didn't want to hijack that thread for a new issue.

@JohnMiller You wrote the nice article on unsubscribing... Any thoughts?

Desperation code

I really figure that 10 times the unsubscribes for every subscribe would stop this. Alas, no.
Keep in mind, this is in addition to unsubscribing when the feature gets turned off. Just to be safe/robust/cover all the bases/find anything that works.

            MessagingCenter.Unsubscribe<SettingsManager, SettingsUpdatedMessage>(this, nameof(SettingsUpdatedMessage));//Avoid duplicate subscriptions
            MessagingCenter.Unsubscribe<SettingsManager>(this, nameof(SettingsUpdatedMessage));//Avoid duplicate subscriptions
            MessagingCenter.Unsubscribe<SettingsManager, SettingsUpdatedMessage>(this, nameof(SettingsUpdatedMessage));//Avoid duplicate subscriptions
            MessagingCenter.Unsubscribe<SettingsManager>(this, nameof(SettingsUpdatedMessage));//Avoid duplicate subscriptions
            MessagingCenter.Unsubscribe<SettingsManager, SettingsUpdatedMessage>(this, nameof(SettingsUpdatedMessage));//Avoid duplicate subscriptions
            MessagingCenter.Unsubscribe<SettingsManager>(this, nameof(SettingsUpdatedMessage));//Avoid duplicate subscriptions
            MessagingCenter.Unsubscribe<SettingsManager, SettingsUpdatedMessage>(this, nameof(SettingsUpdatedMessage));//Avoid duplicate subscriptions
            MessagingCenter.Unsubscribe<SettingsManager>(this, nameof(SettingsUpdatedMessage));//Avoid duplicate subscriptions
            MessagingCenter.Unsubscribe<SettingsManager, SettingsUpdatedMessage>(this, nameof(SettingsUpdatedMessage));//Avoid duplicate subscriptions
            MessagingCenter.Unsubscribe<SettingsManager>(this, nameof(SettingsUpdatedMessage));//Avoid duplicate subscriptions

            MessagingCenter.Subscribe<SettingsManager, SettingsUpdatedMessage>(this, nameof(SettingsUpdatedMessage), (sender, args) =>
            {
                OnSettingsChanged();
            });

How to make Tabbed page of many content page with a scroll menu in Xamarin forms?

Profiler not starting on android

$
0
0

Hello,
I have visual studio 2017 Enterprise 15.5.1. Xamarin forms project for iOS, Android and UWP. The project builds and deploys successfully. When I try to start profiling on attached nexus 6P API -26, it's waiting for device to connect.... and soon after that stopped is shown. On the top the target device is correct, after that package name.SplashActivity. Is this splash activity is some how problem? how i can change it to main activity? or some other problem?

Thank you for your help

RESX with x:static in XAML not working since Forms 2.3.3

$
0
0

Hi

I used to reference strings from resource files like Text="{x:Static base:Resource.RegistrationPage_Module_Continue}" , now since the update to Xamarin Forms 2.3.3 I get the following errors. I've seen the https://developer.xamarin.com/guides/xamarin-forms/advanced/localization/. But is it really now so much more complicated?

Position 10:81. x:Static: unable to find a public static field, static property, const or enum value named {ResourceName} in base:Resource...

Thanks

Assembly Reference Errors despite having the reference and using statements

$
0
0

Hello,
Last night while working on a new Xamarin Forms application for Android, IOS, and Windows I encountered a strange error. I added sql-net-pcl from Nouget to my references. Went to work, adding using statements everywhere I needed them and so on.

However, when I go to build the project, I get 9 errors saying namespace or assembly reference not found. Each project has the sql-net-pcl installed. Every class I touched has its using statements. When I clean the solution, there is no errors. No red lines. Only when I attempt to Build/Launch the project do I get these errors. I just downloaded the sql-net-pcl package last night, so it should be up to date.

Similarly, in my App.cs I made a second constructor with a string parameter. But when I attempt to call new App(string), the compiler thinks it doesn't exist.

Let me know what you think. Thank you. (I am on VS 2017).

Viewing all 204402 articles
Browse latest View live


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