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

What is all this New, Old and Element stuff inside a Custom renderer?

$
0
0

Hi all, I'm building a small library of controls that aren't provided by Xamarin.Forms like Checkboxes and RatingBars. So far they are working well, but I want to know the right way to set up the renderer for them.

Explicitly what is the use of OldElement, NewElement?

Docs only give this template, but I pesonally think that it isn't very instructive:

protected override void OnElementChanged (ElementChangedEventArgs<NativeListView> e)
{
  base.OnElementChanged (e);

  if (Control == null) {
    // Instantiate the native control and assign it to the Control property
  }

  if (e.OldElement != null) {
    // Unsubscribe from event handlers and cleanup any resources
  }

  if (e.NewElement != null) {
    // Configure the control and subscribe to event handlers
  }
}

In which scenarios are OldElement distinct from null and in which is null, and in which is NewElement null or not?

Hope someone could help me to understand.


Xamarin.Forms bug? System.ObjectDisposedException: Cannot access a disposed object

$
0
0

Hi,

My Android Xamarin.Forms application uses a Navigation stack to display various views, I often have a list on a screen (A) that once a cell is clicked I push onto the stack a new screen (B), the user completes some form fields and then clicks a button to save. Once they click the 'save' button a task is created on the thread pool to asynchronously perform some work (no async/await and no dependency on any UI) and the view is popped back to screen (A).

Once the task is completed, it fires a simple event using the PubSub library, on the UI thread, so screen (A) has the opportunity to refresh from the local database and it does.

The problem is that when I go to drag the updated list on screen (A), the app crashes with an ObjectDisposedException intermittently (like 1 in 50 times)...

System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'Android.Views.GestureDetector'.
  at Java.Interop.JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self) [0x00030] in /Users/builder/data/lanes/3819/c1d1c79c/source/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.cs:153
  at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualBooleanMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00002] in /Users/builder/data/lanes/3819/c1d1c79c/source/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:57
  at Android.Views.GestureDetector.OnTouchEvent (Android.Views.MotionEvent ev) [0x0002c] in /Users/builder/data/lanes/3819/c1d1c79c/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Views.GestureDetector.cs:1546
  at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].Android.Views.View.IOnTouchListener.OnTouch (Android.Views.View v, Android.Views.MotionEvent e) [0x0003f] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:101
  at Android.Views.View+IOnTouchListenerInvoker.n_OnTouch_Landroid_view_View_Landroid_view_MotionEvent_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_v, System.IntPtr native_e) [0x00019] in /Users/builder/data/lanes/3819/c1d1c79c/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Views.View.cs:3558
  at at (wrapper dynamic-method) System.Object:4eaabbb9-8c1c-4ea1-b505-44c325bbb1ab (intptr,intptr,intptr,intptr)

I'm not sure why it says that I cannot access a disposed object, I'm interacting with a list with a gesture detector, it's on-screen, so it's not disposed.

Is this a bug in Xamarin.Forms?

On a similar note, if I modify an MVVP property that notifies listeners that a property has changed (I always check it's on the UI thread first), then if that's bound to a Xamarin.Forms list but it's not currently on-screen, presumably Xamarin.Forms will not barf ? After-All it's just off-screen and should still bind okay?

Abandoning Xamarin.Forms :(

$
0
0

Hi there,

over the last months I wrote a quite big business application using forms.
The main target was UWP, but we needed the possibility to create IOS and Android versions along the road.

Overall my impressions were not too good. The goal was that just a few developers could maintain all targets.
In the end most of my time was spend working around bugs in forms and making it behave like I wanted it to.

The backend is a very portable assortment of PCL modules, around a forms host app that should provide the UI
for it, manage navigation and stuff like that. A bad design decision was that, because we had a unified design language,
that modules can provide designs for UI elements, pages and so on directly in Forms code or xaml.

It almost worked, as long as the app was simple, just a few modules providing elements for a dashboard, some process
pages. As it got more complex and flexible (updating, inserting and deleting Elements in real time, lots of more different
Elements from other modules for the dashboard) it began lacking.

What was once very smooth is now flickering and delaying.

But the real problems are, now that the app is almost finished:

  • Every Update somehow breaks something, most of the time the android build needs a day of reading and fixing and manually fixing
    the project files to maybe work again

  • Creating custom renderers for everything. I want a different Titlebar design for Master/Detail pages or a Frame that inexplicably
    doesn't show the rounded border non-transparent or lots of other tweaks I had to research and write one. I even had to write one
    that does a nasty hack for tabbed pages because for whatever reason the tab titles are non formatted or highlighted when using
    it like I should. Also lack of PDF and other very default formats is lacking and needs a custom implementation. I only did this for UWP...I don't even
    want to think about repeating it for Android or IOS

  • Image problems. Using URI Sources just doesn't work sometimes. Images don't show in one place but the same URI shows
    in another. I also had lots of problems when using buffered images and stream sources. For example, they don't show up when used
    in datatemplates in lists, if this datatemplate is defined in a different PCL for whatever reason

  • Random complete UI blocks. I made sure that there is nothing interesting running on the UI thread. And it works most
    of the time just fine. Just randomly blocking UI for about 5-10 seconds. I never found a source for that.

  • Random complete app crashes. The app works fine, concurrency should be good. But repeating the exact same process
    just sometimes results in a uncatched exception with just the text "Unspecified Error" an no further explanation or stack trace

Just the random untraceable crashes are enough to never being able to release it and I'm not confident in posting bug reports for
every little thing i encountered, seeing that bugs from 2 years ago are not yet fixed and the activity on forms is severely lacking in
the last months.

Well, in the end I guess it is my fault. Forms was not the correct target for this application and luckily 90% of the code is reusable.

Sorry for the rant :)

Button on Android all caps

$
0
0

I have just noticed that on Xamarin Forms Android, the text label on elements appears in ALL CAPS. Is this by design?

Regards,
Ian

Xamarin.Forms.UWP crash in OnLaunched() Native Toolchain ON

$
0
0

When build-setting "Compile with .NET Native tool chain" is ON, I get the following exceptions in Xamarin.Forms.Forms.Init(e); in OnLaunched():

Exception thrown: 'System.IO.FileNotFoundException' in System.Private.Reflection.Core.dll
Additional information: Cannot load assembly 'ClrCompression'. No metadata found for this assembly.

Exception thrown: 'System.IO.FileNotFoundException' in System.Private.Reflection.Core.dll
Additional information: Cannot load assembly 'sqlite3'. No metadata found for this assembly.

Exception thrown: 'System.IO.FileNotFoundException' in System.Private.Reflection.Core.dll
Additional information: Cannot load assembly 'ucrtbased'. No metadata found for this assembly.

I can just continue and the app seems to run fine, but when the app is installed from AppStore, it just crashes.

Any ideas?

Tom

How to set Button text without changes (not in uppercase)?

$
0
0

Hello,

I have this xaml for button:

<Button Text="Click here!" Image="icon.png" ContentLayout="Top, 0"/>

But the text is displayed in uppercase and I want it without changes. Is it posible?

Horizontal ListView

$
0
0

Is any way to create listview with horizontal scroll ?
smth like in image.
thanks.

How can we create a chating App in xamarin forms by using signalr?

$
0
0

I want one to one or group chat in xamarin forms?


How to create a rounded first and last cell in ListView Xamarin Forms?

$
0
0

How to create a rounded first and last cell in ListView Xamarin Forms?Can any one tell me how to achieve the first and last cell rounded corners in Xamarin Forms?

Change the keyboard type for SearchBar

$
0
0

We have a page that uses SearchBar, but in one instance, it would be more beneficial for us to be able to use Keyboard.Numeric since we're searching for values that largely contain numbers. Is something like this possible already or do I have to create a custom renderer?

Style FontSize OnPlatform in Xaml

$
0
0

Hi everybody, i'm looking for a way to change the fontsize of all my labels with a style defined in App.xaml (XF 1.3).

But i don't find any way to make it works.
Note : i want to make it with xaml in app.xaml

<Style x:Key="Titre"
       TargetType="ctrls:Label">
    <Setter Property="FontAttributes"
            Value="Bold"/>
    <Setter Property="ctrls:Label.FontSize">
        <Setter.Value>
            <OnPlatform x:TypeArguments="x:Double">
                <OnPlatform.iOS>18</OnPlatform.iOS>
                <OnPlatform.Android>18</OnPlatform.Android>
                <OnPlatform.WinPhone>26</OnPlatform.WinPhone>
            </OnPlatform>
        </Setter.Value>
    </Setter>
</Style>

The bold attribute worked but no luck with fontsize.

I've tryed different solutions :
<OnPlatform.iOS>
18</x :Double>
</OnPlatform.iOS>

Even this line doesn't work :
<Setter Property="FontSize" Value="30"/>

I can declare style for everything except fontsize. What am i doing wrong ?

(please Xamarin Team, do something for the code we paste here : there are always some text hidden, some lines missing etc. I don't know how the hell you came up with such a weird behavior but i d rather prefer simple text without formating that half the code i paste. We are not here to edit our message 10 times. I spend more time editing my code than writing the entire message. Thank you guys)

Exemple : my code OnPlatform.iOS x double 18 shows half the code in my browser. So people will think i don't care about this post because there are code missing but no. The text is just hidden for no reason.

How to Save Entry Value when jumps to another page ?

$
0
0

I have an entry control but I want to add a Text in Entry and Click on Button then it will jump to next page but when I revert back I want that my Entry Message exists in the Entry Control ?
What can I do to achieve that kind of functionality ? ?

Visual Studio 2015 Community - How to Upgrade XForms From 2.0.... to 2.3.3....

$
0
0

Hi there!
Is there a step by step tutorial about how to upgrade Xamarin Forms to 2.3.3. release?

Many thank for any kind of help.

Best regards,
Ciro.

Create a Window pop-up

$
0
0

Hello,
I'm actually making an application on Xamarin and I have a question. How can I make a Pop-up Window like the picture and get back the clicked value ?

Thank you very much for your time.

Karim Flaction

GetItemsAsync seems to return nothing from table.

$
0
0

Hi guys,

I've got an issue where I've been following the guide on working with a local database, as well as the associated repo.

I've managed to connect to the database and add items to it, but it would seem as if the list that I'm returning from the database always has a count of 0.

As mentioned the database adds items just fine. In the following snippet I'm adding the result of a HTTP Get-request in the form of a deserialized JSONarray (currently a List):

        protected override async void OnAppearing()
        {
                base.OnAppearing();
                App.Database.Tester();
                var result = await App.Database.GetItemsAsync();
                Debug.WriteLine("Debugger: " + result.Count);
                ListView lv = lvResults;
                // Reset the 'resume' id, since we just want to re-start here
                lvResults.ItemsSource = result;
        }

Sorry for the ugly code. As mentioned above the count is always 0. Even if I've run through saving all the items:

            var result = await GetAllFoundationsAsync();

            for (var i = 0; i < result.Count; i++)
            {
         Debug.WriteLine(result[i].ToString()); //overridden, so shows a few values of each foundation in a pretty-string.
                 await App.Database.SaveItemAsync(result[i]);
            }

after which I can see that the output shows me each individual result and add it to the database with no visible error.

After having added all the items I then see if the code in onAppearing() will give me anything; but it still does nothing. So I've stepped through the code both from a default perspective (without saving anything before-hand) and after having saved them to the database.

Below you will see my database and object-classes. Before that I want to mention that I've stepped through the whole project and have not encountered any issues; the breakpoints get invoked in both onAppearing and in the database-class (both in the SaveItemsAsync and in GetItemsAsync), but either the database is truly empty, or I'm doing something wrong somewhere else...

This is the foundation class:

namespace App3
{
    public class Foundation
    {
        [PrimaryKey, AutoIncrement]
        public int? ID { get; set; }
        public int? FoundationID { get; set; }
    //There are more attributes, but it's not necessary to show them all.

        public string Summary
        {

            get {
                Debug.WriteLine("Getting Summary");
                return String.Format("Id: {0}, Added by {1}", ID, EngineerName);}
        }

        public override string ToString()
        {
            var out_string = string.Format("ID: {0},@Engineer Name: {1},@Signature: {2},@Date: {3}", ID, EngineerName, EngineerSignature, EngineerDate);
            out_string.Replace("@", Environment.NewLine);
            return out_string;
        }
    }

    public class FoundationObject
    {
        public Foundation[] foundations { get; set; }
    }
}

And this is the database-class:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Diagnostics;
    using System.Threading.Tasks;
    using SQLite;

    namespace App3
    {
        public class FoundationsDatabase
        {

            readonly SQLiteAsyncConnection db;

            public FoundationsDatabase(string dbPath)
            {
                db = new SQLiteAsyncConnection(dbPath);
                db.CreateTableAsync<Foundation>().Wait();
            }

            public Task<List<Foundation>> GetItemsAsync()
            {
                var data = db.Table<Foundation>().ToListAsync();
                Debug.WriteLine("DATA: " + data);
                return db.Table<Foundation>().ToListAsync();
            }

            public void Tester()
            {
                Debug.WriteLine("QUERY: " + db.QueryAsync<Foundation>("SELECT * FROM [Foundation]"));
            }

            public Task<List<Foundation>> GetItemsAsync(int id)
            {

                return db.Table<Foundation>().Where(i => i.ID == id).ToListAsync();

            }

            public Task<int> SaveItemAsync(Foundation item)
            {
                if (item.ID != 0){
                    return db.UpdateAsync(item);
                } else{
                    return db.InsertAsync(item);
                }
            }

            public Task<int> DeleteItemAsync(Foundation item){
                return db.DeleteAsync(item);
            }
        }
    }

Don't work padding in stacklayout

$
0
0

I work with Xamarin Forms. Don't work padding in stacklayout. I have:******

<StackLayout>
        <StackLayout>
          <!--Code. It not have padding.-->
        </StackLayout>
        <StackLayout>
          <StackLayout.Padding>
            <Thickness Right="5" Left="5" Top="5" Bottom="5"/>
          </StackLayout.Padding>
          <!--It must have padding-->
       </StackLayout>
     </StackLayout>

Why it's not working?

MasterDetailPage Fixed icon menu

$
0
0



Hi, they have some idea how to leave the icon of the hamburgesa fixed, while navigating to the pages of the menu, of my main page, the images illustrate a little the effect that I want to bind instead of the icon to return back. That is the one of the hamburger.

Thanks in Advance

Not able to integrate urban airship sdk in xamarin forms

$
0
0

Hi I am new to xamarin forms. I was trying to integrate urbanairship sdk with my project but its giving me lot of compilation error. it might be due to version compatibility in xamarin. Can anyone please tell me which versions are compatibles of support and gcm library with urbanairship and xamarin forms.

Using FAB.forms ?

$
0
0

I am trying to add a Flating Action Button to a simple listview using FAB.forms but nothing is appearing & there are no build errors.

I have added FAB.forms v2.1.1 to a XAmarin Forms PCL project and also added Xamarin.Android.Support.Design to Android Packages.

Following the provided guides I have constructed my XAML page as follows

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:FABTest"
             xmlns:fab="clr-namespace:FAB.Forms;assembly=FAB.Forms"
             x:Class="FABTest.Contacts" >
  <ContentPage.Content>
        <RelativeLayout>
            <ContentView
                RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1, Constant=10}"
                RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1, Constant=10}">
    <ListView x:Name="EndpointListView" ItemsSource="{Binding Items}" IsVisible="{Binding IsListVisible}" HasUnevenRows="True" SeparatorColor="{DynamicResource ListViewSeparatorColor}" >
      <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <Label Text="{Binding Name}" />
            </ViewCell>
        </DataTemplate>
      </ListView.ItemTemplate>
    </ListView>
  </ContentView>
            <fab:FloatingActionButton
                x:Name="fabBtn"
                Source="plus.png"
                Size="Normal"
                Clicked="Handle_FabClicked"
                NormalColor="Green"
                RippleColor="Red"
                RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=-50}"
                RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=-50}" />
        </RelativeLayout>
    </ContentPage.Content>
</ContentPage>

Are there other additional packages I should be using to get this working?

Navigation Master page detail to Normal page.

$
0
0

Hi All,

My requirement is i want to navigate master page detail to normal page how can i do that.

Can anyone please help me??

Viewing all 91519 articles
Browse latest View live


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