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

Pre-built Xamarin Presentations & Workshops


Strange behavior with Animations and Stackpanel on iOS

$
0
0

Hello together,

we have built our own ItemsControl for our application. The control derives from the StackLayout, which can be bound to a collection and creates the childs for the StackLayoutvia DataTemplate.
So far so good. The items in the control can be moved up and down. As soon as an item of the bound collection is moved, an animation starts, which visualizes the movement. This works perfectly on Android devices, only on iOS there is a problem. After moving the items in the StackLayout, one of the items is no longer displayed in the right place.

We execute the animation as follows:

await Task.WhenAll(affectedByPositionChange.FadeTo(0, 250, Easing.SinInOut), affectedByPositionChange.TranslateTo(0, translation1, 500, Easing.SinInOut));
await positionChangeToggled.TranslateTo(0, translation2, 500, Easing.SinInOut);
await affectedByPositionChange.FadeTo(1, 250, Easing.SinInOut);
positionChangeToggled.TranslationY = affectedByPositionChange.TranslationY = 0;

After the animation has been performed, the position of the items in the StackLayout is swapped.

var itemView = layout.Children[e.OldStartingIndex];
layout.Children.RemoveAt(e.OldStartingIndex);
layout.Children.Insert(e.NewStartingIndex, itemView);

But now the item that was moved down is displayed in the wrong position. See the attached picture.

We fixed this behavior:
Solution 1 => Using Device.BeginInvokeOnMainThread

Device.BeginInvokeOnMainThread(() =>
{
    layout.Children.RemoveAt(e.OldStartingIndex);
    layout.Children.Insert(e.NewStartingIndex, itemView);
});

Solution 2 => Remove and insert both items

var itemView = layout.Children[e.OldStartingIndex];
var itemView2 = layout.Children[e.NewStartingIndex];
layout.Children.Remove(itemView);
layout.Children.Remove(itemView2);
layout.Children.Insert(e.NewStartingIndex, itemView);
layout.Children.Insert(e.OldStartingIndex, itemView2);

All this is currently executed in the CollectionChanged handler of the bound collection. Therefore we had already tried to execute the complete code within Device.BeginInvokeOnMainThread. So every action concerning the UI elements is running on the UI-Thread. This didn't work as expected, the visualization of the StackLayout items is still false.

We have now a solution, but we would like to know what exactly goes wrong here? Why doesn't it work when we run everything on the UI-Thread.

Cell dimensions of a grid isn't consistent when scaling the content inside it

$
0
0

Hello,

I have a grid contain a Lottie animation (named as "animationView") in the cell of the first row and column.

During run time, when the user press the animation, I scale It to a new size:

await animationView.ScaleTo(0.333);

The problem is that the dimensions of the cell isn't change with it, and as a result there is a lot of space left between the animation and the cell border.

Unfortunately, setting the cell row and column definition to AUTO, isn't help...

I dedicated a lot of time trying to solve it, with out any success.

Any help will be appreciate!

App doesn't load all the jpgs

$
0
0

Hi there guyz. This is my first question here. I've encountered a problem concerning jpgs in my Xamarin.Forms app. Since there is no nice way of displaying pdf in Xamarin i've split my pdf file into jpg images. On my emulator all the images are shown, but on some other devices - not all of them, only a few. Maybe someone has a clue of what's going on?
P.S. Images are in the drawable folder and all set to "Android Resource"

Consuming a DataTemplateSelector in a single ContentView : No ListView

$
0
0

Hello everyone.

What I try to do
Consume a DataTemplateSelector for a single item => not a ListView which would have made things very easy. I don't need a ListView because each template might use a ListView (and we know that a ListView inside a ListView isn't the best idea) and I only have one template to display. Not a list.

What I used to do
In the past, I would have used several element with a binding on the IsVisible property and use a converter to chose which element should be visible.
E.G (I simplified the content but imagine that instead of Label, there would have a custom ContentView) :
<StackLayout>
<Label IsVisible="{Binding Team, Converter={StaticResource TeamToVisibilityConverter}, ConverterParameter='1'" Text="Template1"/>
<Label IsVisible="{Binding Team, Converter={StaticResource TeamToVisibilityConverter}, ConverterParameter='2'" Text="Template2"/>
<Label IsVisible="{Binding Team, Converter={StaticResource TeamToVisibilityConverter}, ConverterParameter='3'" Text="Template3"/>
</StackLayout>

What I'd like to do
<ContentView BindingContext="{Binding Team}">
<ContentView.ControlTemplate>
<ControlTemplate DataTemplateSelector.ElementTemplateContent="{StaticResource TeamTemplateSelector}" />
</ContentView.ControlTemplate>
</ContentView>

I would like to make things smarter. I'm trying to figure out how to use a DataTemplateSelector for a single ContentView.

Do anyone have found something interesting : a smart way to accomplish what I'm looking for ?
The closest thing I found is https://forums.xamarin.com/discussion/84810/datatemplates-and-contentcontrols#latest
But I think and hope there is a better way to do that in 2019 :D

PS : there isn't any topic on that on the documentation and I only found exemple with ListView.

Workaround found
Use the BindableLayout with a collection of one item. But IMHO, that's far from the best option and it requires to either have a converter that return a list from a single object or to add a collection of a single element in the view model.

Thanks everyone.

how to make the top nav bar invisible when using shell?

$
0
0

I'm trying to use shell , but I want to customize y top nav bar , I tried to find something to change the bachground color and the title color but I didn't find anything, so I thought I can get the navigation bar invisible and do my own but the normal method woudn't work because I think we are not using NavigationPage.
does any one has an idea about this.
thnx.

Xamarin Forms List View doesn't display added items instantly with Observable Collection

$
0
0

I'm trying to verify if ListView displays or refreshes items instantly whenever we add an object to the Observable Collection, but it doesn't. I have tested in Debugging mode in Visual Studio, and ListView only displays items once all the objects have been iterated and added to the Observable Collection (for e.g. in the below Subscribe method). What am I missing?

Note: I've also applied INotifyPropertyChanged both on underlying Model and ViewModel (Page1 in this example) so that ListView can listen to property changed event of collection as well, but no luck.

Here's the code example:

public partial class Page1 : ContentPage, INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        ObservableCollection<TestModel> trackListObservable;
        public ObservableCollection<TestModel> Items
        {
            get { return trackListObservable; }
            set
            {
                trackListObservable = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs(nameof(Items)));
                }
            }
        }

        public Page1 ()
        {
            InitializeComponent ();
            Items = new ObservableCollection<TestModel>();
            BindingContext = Items;
        }

        protected override void OnAppearing()
        {
            base.OnAppearing();

            List<int> test = new List<int>() { 1, 2, 3, 4, 5 };

            test.ToObservable()
                .SelectMany(x => Observable.Start(() => Increment(x)))
                .Select(x => x)
                .Subscribe(result => Device.BeginInvokeOnMainThread(() => {
                    Items.Add(new TestModel() { Number = result });
                }));
        }

        int Increment(int num)
        {
            return num++;
        }
    }

    public class TestModel : INotifyPropertyChanged
    {
        private int number;

        public int Number
        {
            get { return number; }
            set
            {
                number = value;
                OnPropertyChanged(nameof(Number));
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        private void OnPropertyChanged(string name)
        {
            if (PropertyChanged == null)
                return;
            PropertyChanged(this, new PropertyChangedEventArgs(name));
        }

    }

App update causes Keychain data loss

$
0
0

Good day
I have an app that stores sensitive data in local keychain of iOS device. It works fine. But if the app is updated with the new version, the data in the keychain is lost. It seems that the stored data does not exist anymore.
Any clues?
[Built using Xamarin.Forms 3.3.0.967583]


Automatic Provisioning failed

$
0
0

Error is : Automatic Provisioning failed: An App ID with Identifier '*' is not available. Please enter a different string.

I have got Xcode installed and it works fine. I can create a brand new test app, automatic signing and Xcode managed provisioning profiles, paid Apple account, all works and I can run/debug on the device.

A new installation of VS for Mac, I cannot even get off the starting blocks. The "Automatic Provisioning" doesn't work. I always get the above error when selecting the team.

I have tried two independent paid Apple accounts and both have the same problem.

It works flawlessly in Xcode so I can only assume that theres no problem with the Apple IDs I'm using or the configuration of profiles and certificates - unless it needs something Xcode doesn't need?

I've tried different bundle IDs and app names but to no avail.

What else can I do or check?

Some kind of security exception that I cannot trace to my own code

$
0
0

I was hoping someone would recognize this stack trace, as I cannot trace the error to my own code so I don't know how I can solve it:

Xamarin Exception Stack:
System.ArgumentNullException: Value cannot be null.
Parameter name: obj
  at (wrapper managed-to-native) System.Object.__icall_wrapper_mono_monitor_enter_v4_internal(object,intptr)
  at Mono.Net.Security.MobileAuthenticatedStream.get_IsAuthenticated () <0xbfb769b8 + 0x00043> in <09a58032fad04aa88077f64ffdcf83b6>:0
  at Mono.Net.Security.MobileAuthenticatedStream.get_CanRead () <0xbfb76c10 + 0x00017> in <09a58032fad04aa88077f64ffdcf83b6>:0
  at System.Net.Security.AuthenticatedStream..ctor (System.IO.Stream innerStream, System.Boolean leaveInnerStreamOpen) <0xbfc35170 + 0x0004b> in <09a58032fad04aa88077f64ffdcf83b6>:0
  at Mono.Net.Security.MobileAuthenticatedStream..ctor (System.IO.Stream innerStream, System.Boolean leaveInnerStreamOpen, System.Net.Security.SslStream owner, Mono.Security.Interface.MonoTlsSettings settings, Mono.Security.Interface.MonoTlsProvider provider) <0xbfb75568 + 0x00067> in <09a58032fad04aa88077f64ffdcf83b6>:0
  at Mono.Btls.MonoBtlsStream..ctor (System.IO.Stream innerStream, System.Boolean leaveInnerStreamOpen, System.Net.Security.SslStream owner, Mono.Security.Interface.MonoTlsSettings settings, Mono.Security.Interface.MonoTlsProvider provider) <0xbfb7f9b4 + 0x0001b> in <09a58032fad04aa88077f64ffdcf83b6>:0
  at (wrapper remoting-invoke-with-check) Mono.Btls.MonoBtlsStream..ctor(System.IO.Stream,bool,System.Net.Security.SslStream,Mono.Security.Interface.MonoTlsSettings,Mono.Security.Interface.MonoTlsProvider)

Thread 2:
0   android.os.MessageQueue.nativePollOnce(MessageQueue.java:-2)
1   android.os.MessageQueue.next(MessageQueue.java:325)
2   android.os.Looper.loop(Looper.java:142)
3   android.app.ActivityThread.main(ActivityThread.java:6938)
4   java.lang.reflect.Method.invoke(Method.java:-2)
5   com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
6   com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

Thread 8834:
0   java.lang.Object.wait(Object.java:-2)
1   java.lang.Daemons$ReferenceQueueDaemon.runInternal(Daemons.java:178)
2   java.lang.Daemons$Daemon.run(Daemons.java:103)
3   java.lang.Thread.run(Thread.java:764)

Thread 8835:
0   java.lang.Object.wait(Object.java:-2)
1   java.lang.Object.wait(Object.java:422)
2   java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:188)
3   java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:209)
4   java.lang.Daemons$FinalizerDaemon.runInternal(Daemons.java:232)
5   java.lang.Daemons$Daemon.run(Daemons.java:103)
6   java.lang.Thread.run(Thread.java:764)

Thread 8836:
0   java.lang.Thread.sleep(Thread.java:-2)
1   java.lang.Thread.sleep(Thread.java:373)
2   java.lang.Thread.sleep(Thread.java:314)
3   java.lang.Daemons$FinalizerWatchdogDaemon.sleepFor(Daemons.java:342)
4   java.lang.Daemons$FinalizerWatchdogDaemon.waitForFinalization(Daemons.java:364)
5   java.lang.Daemons$FinalizerWatchdogDaemon.runInternal(Daemons.java:281)
6   java.lang.Daemons$Daemon.run(Daemons.java:103)
7   java.lang.Thread.run(Thread.java:764)

Thread 8844:
0   java.lang.Object.wait(Object.java:-2)
1   java.lang.Thread.parkFor$(Thread.java:2135)
2   sun.misc.Unsafe.park(Unsafe.java:358)
3   java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:230)
4   java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2101)
5   java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.poll(ScheduledThreadPoolExecutor.java:1168)
6   java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.poll(ScheduledThreadPoolExecutor.java:1147)
7   java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1086)
8   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1147)
9   java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
10  java.lang.Thread.run(Thread.java:764)

Thread 8846:
0   java.lang.Object.wait(Object.java:-2)
1   java.lang.Thread.parkFor$(Thread.java:2135)
2   sun.misc.Unsafe.park(Unsafe.java:358)
3   java.util.concurrent.locks.LockSupport.park(LockSupport.java:190)
4   java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2059)
5   java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
6   java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1087)
7   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1147)
8   java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
9   java.lang.Thread.run(Thread.java:764)

Thread 8851:
0   android.os.MessageQueue.nativePollOnce(MessageQueue.java:-2)
1   android.os.MessageQueue.next(MessageQueue.java:325)
2   android.os.Looper.loop(Looper.java:142)
3   android.os.HandlerThread.run(HandlerThread.java:65)

Thread 8853:
0   android.os.MessageQueue.nativePollOnce(MessageQueue.java:-2)
1   android.os.MessageQueue.next(MessageQueue.java:325)
2   android.os.Looper.loop(Looper.java:142)
3   android.os.HandlerThread.run(HandlerThread.java:65)

Thread 8854:
0   android.os.MessageQueue.nativePollOnce(MessageQueue.java:-2)
1   android.os.MessageQueue.next(MessageQueue.java:325)
2   android.os.Looper.loop(Looper.java:142)
3   android.os.HandlerThread.run(HandlerThread.java:65)

How call a command when an event is triggered?

$
0
0

I have relativeLayout and me need load data when relative layout showed.
How can I implement this?

How to deploy to my plugged in phone and not to the emulated android?

$
0
0

In Visual Studio when I want to run my project, my only choice now is the Android_Accelerated_X86_Oreo emulator. I would like to deploy to my cell phone. I have been able to do that but suddenly I cannot. I have Dev Options enabled and the USB connection is in File Transfer mode. What am I doing wrong?

SkiaSharp with Pan and Zoom and pin painting

$
0
0

i am looking for how to implement SkiaSharp with Pan and Zoom and pin painting after edit the image save it
Any one have idea to fo that

thanks.

Remove xaml.g.cs file from Go To Declaration

$
0
0

In Visual Studio for Mac I often right click an object, select Go to Declaration and sometimes there is a list below that: one pointing to the .cs file and on pointing to the .g.cs file. This is driving me absolutely nuts for quite a while now, I have never wanted to go to the generated file ever.

So how do I remove the xaml.g.cs from "Go To Declaration" submenu?

Issue on iOS when pushing modal on master detail during application startup.

$
0
0

I have an unusual problem only appearing on iOS. After setting the main page (master detail) I am doing long asynchronous task. When this task is finished I am pushing modally another page like this:

MainPage = new MasterDetail();
await FetchSthFromDb();
MainPage.Navigation.PushModalAsync(new SomePage());

I got the following error:

Warning: Attempt to present <Xamarin_Forms_Platform_iOS_ModalWrapper: 0x7f9eb84694f0> on <Xamarin_Forms_Platform_iOS_PlatformRenderer: 0x7f9eb8444d80> whose view is not in the window hierarchy!

This error only appears on iOS. On Android everything is working fine. Did anyone encounter sth similar?


How to turn off keyboard suggestions when editing axml?

$
0
0

They are in all cases useless. When I am creating axml and press the return key, VS shows me suggestions as in the image

I assume the suggestions reflect the fact there is nothing at the current position in the file, like when I press return and am on a new line.

It's also the same when I try to neaten up the messy axml but going to the line and pressing the tab key. I have to use the menu selection for Increase Indent, which is not awful but should be unnecessary.

Is there an Option setting I'm overlooking?

Json array to Picker in Xamarin Forms

$
0
0

Hello,

First of all Im scanning the qr code with the application, then the app is making api request and I get json in my response from my server..

I want to get a json from my api and display it in picker in xaml, let me show you my json

{"20":[{"stroke":"25","id":"1222","price":"118.00"},{"stroke":"40","id":"1224","price":"121.60"},"25":[{"stroke":"25","id":"1247","price":"126.75"},{"stroke":"40","id":"1248","price":"130.80"},........

Where "20" and "25" are the diameters and must be unique values that have to be in the 1st picker while in the 2nd picker I need to have stroke, id and price.

Here is my model;

public class Silowniki
    {
        //public string Dia { get; set; }
        public string stroke { get; set; }
        public string id { get; set; }
        public string cena { get; set; }
    }

    public class Diameter
    {
        public List<Silowniki> diameter { get; set; }
    }

My viewmodel

public class ScannedViewModel : INotifyPropertyChanged
    {
        public ObservableCollection<Silowniki> Silowniki { get; set; }
        public ObservableCollection<Diameter> Dia { get; set; }

        public string Test { get; set; }

        public ScannedViewModel()
        {
            Silowniki = new ObservableCollection<Silowniki>();
            Dia = new ObservableCollection<Diameter>();
        }

My json response here:

if (response.StatusCode == HttpStatusCode.OK)
                {
                    Console.WriteLine("Tutaj jest twoj response");
                    var a = JsonConvert.DeserializeObject(responseText);
                    Debug.WriteLine(a);
                    //Console.WriteLine(a);
                    return a;

And here is how I add the json to diameter, I doubt its the right way..

    public Diameter MyDia { get; set; }
    ScannerPage.OnScanResult += (result) =>
                    {
                        ScannerPage.IsScanning = false;
                        Device.BeginInvokeOnMainThread(async () =>
                        {
                            await Navigation.PopAsync();
                            dynamic jsonRespone = await ConnectWithOauth.GetRequest(result.Text);
                            JObject parsedJson = JObject.Parse(jsonRespone);

                            MyDia = JsonConvert.DeserializeObject<Diameter>(jsonRespone);
                            //Console.WriteLine(MyDia);
                            //Console.WriteLine(jsonRespone);
                            //SaveProducts(parsedJson, viewModel);
                            viewModel.Dia.Add(MyDia);
                            ScannedProducts nextPage = new ScannedProducts(viewModel);
                            nextPage.BindingContext = viewModel;
                            Console.WriteLine("Pokaz mydia count: " + MyDia.diameter.Count);
                ^- Here im getting error from the compiler
                            await Navigation.PushAsync(nextPage);

I have also tried with my "SaveProducts" function here it is:

async public void SaveProducts(dynamic json, ScannedViewModel model)
        {
            //ScannedProducts nextPage = new ScannedProducts(model);
            foreach (var item in json)
            {
                foreach (var prop in item)
                {
                    foreach (var test in prop)
                    {
                        Silownik = new Silowniki
                        {
                            //Dia = item.Name,
                            stroke = Convert.ToString(test[0]).Split(':')[0],
                            id = Convert.ToString(test[0]).Split(':')[1],
                            cena = Convert.ToString(test[0]).Split(':')[2]
                        };
                        //Console.WriteLine(Silownik.Dia + ":" + Silownik.Cena);
                        try
                        {
                            model.ItemOb.Add(Item);
                            model.Silowniki.Add(Silownik);
                            model.Dia.Add(MyDia);
                        }
                        catch (Exception e)
                        {
                            Debug.Write(e);
                        }
                    }
                }
            }

And lastly here is my xaml and Im 100% sure its wrong..

    <StackLayout x:Name="myStackLayout">
        <Label
                x:Name="idKlienta"
                VerticalOptions="CenterAndExpand" 
                HorizontalOptions="CenterAndExpand" />
        <Picker Title="Wybierz Diameter" 
                ItemsSource="{Binding Dia}"
                ItemDisplayBinding="{Binding Silowniki.stroke}">
        </Picker>
        <Picker Title="Skok"
                ItemsSource="{Binding Dia}"
                ItemDisplayBinding="{Binding Silowniki}">
        </Picker>

Please help me Im stuck in this for past 2 days and I really dont know what to do next...

ObjC-C# binding, native 'init' returns nil

$
0
0

Hello,

I am extending the Xamarin. SoupChef example to implement my own Intent. I correctly generated the library following the example in SoupChef, but when I try to reference it in the app (I am using the SoupChef app), i receive the following error:

Could not initialize an instance of the type 'SoupChef.SendCommandIntent': the native 'init' method returned nil.
It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false.

I checked all the steps to generate the library, and including it in the original SoupChef.OrderSoupIntentBinding, including registering the intents in its Info.plist. But when it comes to using it, i get the error. Some code follows

// Order.cs
public OrderSoupIntent Intent
{
       get
       {
            *var myIntent = new SendCommandIntent(); // Only added this line!!!*
             var orderSoupIntent = new OrderSoupIntent();
             orderSoupIntent.Quantity = new NSNumber(Quantity);
             orderSoupIntent.Soup = new INObject(MenuItem.ItemNameKey, MenuItem.LocalizedString);

Exception is thrown here (file SendCommandIntent.g.cs)

[BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)]
[EditorBrowsable (EditorBrowsableState.Advanced)]
[Export ("init")]
public SendCommandIntent () : base (NSObjectFlag.Empty)
{
    IsDirectBinding = GetType ().Assembly == global::ApiDefinitions.Messaging.this_assembly;
    if (IsDirectBinding) {
HERE--> InitializeHandle (global::ApiDefinitions.Messaging.IntPtr_objc_msgSend (this.Handle, global::ObjCRuntime.Selector.GetHandle ("init")), "init");
    } else {
        InitializeHandle (global::ApiDefinitions.Messaging.IntPtr_objc_msgSendSuper (this.SuperHandle, global::ObjCRuntime.Selector.GetHandle ("init")), "init");
    }

}

Can anyone help me please?
Paolo

Notification Hub Redirection in IOS

$
0
0

Hello Developers,

i'm using xamarin forms
The app works great - the app registers for push notifications, and push notifications are received successfully from Azure Notification Hubs on iOS and Android

i did some research. i found the same question and the response was for android only
link : https://forums.xamarin.com/discussion/40352/how-to-go-to-specific-page-when-user-clicks-on-push-notification

how do I get my app to launch into or display a specific page when the user taps on a push notification on IOS,
Thank you.

get Power fail/restart exceptions during Android native debugging

$
0
0

Hi! I got many "power fail/restart" exceptions on uncertain locations during native debugging. I guess what caused it is that I access sensors data by sensor manager. I can't show my code and I remove my all C++ code won't stop this. Can you tell what cause this exactly? How can I get through this?

Thanks a lot for your helping.

Viewing all 204402 articles
Browse latest View live


Latest Images

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