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

Java.lang.ClassCastException in NavigationPageRenderer.Dispose(bool)

$
0
0

I am seeing a number of unhandled exceptions when resetting the navigation stack (I use Prism as my MVVM framework) using an absolute page URL, like

navigationService.NavigateAsync("/NavigationPage/path/to/new/page");

The exception occurs when the current navigation stack is being torn down and the NavigationPageRenderer is disposing of all of its resources. The exact statement throwing the exception is

FragmentManagerExtensions.ExecutePendingTransactionsEx

and the message from the exception is

com.google.maps.api.android.lib6.impl.ao cannot be cast to android.view.ViewGroup

I am using Xamarin.Forms.Maps and Xamarin.GooglePlayServices.Maps along with Xam.Plugin.Geolocator for geolocation.

I posted a bug report in the Xamarin.Forms github repository and the URL for it is here: https://github.com/xamarin/Xamarin.Forms/issues/7874

Has anyone experienced anything like this?

Thanks,
Matthew


How to set hamburger icon flow direction to right

$
0
0

Hi
I want to set hamburger icon and back button in navigation page to the right. I did that by following this answer . But this answer didn't mentioned how to do it in iOS, so it only worked with android. I didn't find any helpful results in my search. So how to do it in iOS ?
thank you

Simple "one" line code with making alert sound notification (beep beep...)?

$
0
0

Hello, I am trying find any simple "one" line code solution for simply make some sound from my samsung watch. Not whole notification, just make some sound so I get client attention.

Vibrate is easy:
var duration = TimeSpan.FromSeconds(1); Vibration.Vibrate(duration);

Why it cant do with sound?

Android app crashes with android.os.RemoteException

$
0
0

The app is crashed with the following app center log, I have tried many ways to reproduce it, but I can't reproduce it. Could you please share your input if you have already experienced with this kind of crash?

at android.os.RemoteException: Remote stack trace:
at com.android.server.am.ActivityManagerService.isTopOfTask(ActivityManagerService.java:18132)
at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:2058)
at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:4144)
at android.os.Binder.execTransact(Binder.java:739)

Few observations.
1. It happens only on the Android 9 devices.
2. It happens when the app is launched or resumed from background.

Thanks,

DisplayAlert not rendering/showing Accept and Cancel options

$
0
0

After Updating to Xamarin Forms 5.0.0.1931 in my project, there are not Yes/No options to close an alert
My code:

private async void ResetStatsButton_OnClicked(object sender, EventArgs eventArgs)
{
if (await DisplayAlert("Alert", "Are you sure you want to reset statistics? (They will be gone forever)", "Yes",
"No"))
{
ResetTable();
}
}

Did this happen to anyone?

FadeTo on Label after showing

$
0
0

Hello
they can't find a way to use FadeTo on a Label once the Label is shown (isVisible = true).
The Label should disappear (fade-out) after about 2 seconds.

I am using MVVM pattern. In ViewModel, I set the visibility flag to Label.
I have tried Triggers (EnterTriger, XAML) but cannot cope with the asynchronous FadeTo call.

How to do it well?

Strange Expander behaviour

$
0
0

Hi,

Trying to use Expander in our app and have strange issue - content view shrinks with each expand/collapse. So when expanded first time it shows content properly and then with each collapse/expand content height gets smaller until completely disappears.

Expander is inside StackLayout, so there is Expander and ListView controls. If I remove ListView then it works fine. Even if ListView is empty it still shrinks.

<StackLayout Orientation="Vertical">
        <xct:Expander Margin="10,0,0,0">
            <xct:Expander.Header>
                <Grid>
                    <Label Text="Total" FontAttributes="Bold"/>
                </Grid>
            </xct:Expander.Header>
            <xct:Expander.ContentTemplate>
                <DataTemplate>
                    <Grid Padding="10">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <Label Text="Stock Total" FontAttributes="Bold" />
                        <Label Text="{Binding Job.totalTP}" FontAttributes="Bold" Grid.Column="1" />
                    </Grid>
                </DataTemplate>
            </xct:Expander.ContentTemplate>
        </xct:Expander>

    <ListView>
    </ListView>
</StackLayout>

AdMob and mediation

$
0
0
AdMob works fine in my Xamarin.Forms App, but I have a ecpm just something around 1€, so I wanted to use mediation throu AdMob to increase the ecpm.
Is it right that I need for each advertiser a seperate sdk? Is there a list with sdks for xamarin, because the most I found dont work with xamarin.
I've tried to work with facebook audience, but I have issues with the aar binding. I get a lot of binding errors when I try to build the aar-binding dll...
So please boys and girls, help me :)

Has rendering of the Label Text property been broken in XF 5.0 on UWP ?

$
0
0

Is anybody else seeing issues updating the Text property of Labels using XF 5.0 on UWP?

I've just migrated from XF 4.8 to 5.0, and the following line of code no longer results in the UI updating on UWP (it's fine on Android).

_statusLabel.Text = _statusLabel.Text + "\r\n" + newItem;

The Text property of the Label object is updated, and if the app window is re-sized (including maximised or restored) the value of the Text property will be reflected in the visible UI. However, without re-sizing the app window, the Text property is not shown in the visible UI.

I've removed custom renderers and the issue still arises. I'll start delving into it further, but wondered if anybody else is seeing this too?

Drag Text over an image

$
0
0

Hi there
I have an image on part of a page that I want a user to be able to position multiple labels over. I thought it would make sense to allow a user to drag the labels to the position on the image they want.

The image is not full screen and there are some other fields on the page so I only what the labels to be able to be moved within the image.

My first attempt was with a Pan gesture:
This allows for an absolute layout that the labels can be on top of. The pan gesture can also be capped.
The pan gesture however seems to be the opposite of what I want in that the pan is actually on the parent (so the image) and not on the label. I can make it so the label is only able to move within the bounds of the image. But instead of dragging the label to move it, you drag the image.

I followed the tutorial from Microsoft as a guide:
https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/gestures/pan

I have a Pan Container with the gesture.

 public PanContainer()
        {
            var panGesture = new PanGestureRecognizer();
            panGesture.PanUpdated += OnPanUpdated;
            GestureRecognizers.Add(panGesture);
        }

        void OnPanUpdated(object sender, PanUpdatedEventArgs e)
        {
            switch (e.StatusType)
            {
                case GestureStatus.Running:
                    // Translate and ensure we don't pan beyond the wrapped user interface element bounds.

                    //This is the parent Absolute layout bounds size - Content.Width
                    //Screen width = 960 (Constant) expected
                    //e.totalX = movement.
                    //x is current position.

                    //The current position + the dragged position.
                    double calculateXValue = x + e.TotalX;
                    double calculateYValue = x + e.TotalY;

                    //The second frame is center so divide by 2 to get the bounds.
                    double capX = Content.Width / 2;
                    double capY = Content.Height / 2;

                    double calculateXValueMax = capX;
                    double calculateXValueMin = capX * -1;

                    double calculateYValueMax = capY;
                    double calculateYValueMin = capY * -1;

                    //Cap the motion to the edges
                    if (calculateXValue >= calculateXValueMax)
                    {
                        calculateXValue = calculateXValueMax;
                    }
                    else if(calculateXValue <= calculateXValueMin)
                    {
                        calculateXValue = calculateXValueMin;
                    }

                    if (calculateYValue >= calculateYValueMax)
                    {
                        calculateYValue = calculateYValueMax;
                    }
                    else if (calculateYValue <= calculateYValueMin)
                    {
                        calculateYValue = calculateYValueMin;
                    }

                    Content.TranslationX =
                        calculateXValue;
                    //Math.Max(Math.Min(0, x + e.TotalX), -Math.Abs(Content.Width - App.ScreenWidth)); // = -344
                    Content.TranslationY =
                        calculateYValue;
                      //Math.Max(Math.Min(0, y + e.TotalY), -Math.Abs(Content.Height - App.ScreenHeight));
                    break;

                case GestureStatus.Completed:
                    // Store the translation applied during the pan
                    x = Content.TranslationX;
                    y = Content.TranslationY;
                    break;
            }

I have a View that is then the label that I want to be able to click and drag.

<ContentView.Content>
        <AbsoluteLayout>
            <Frame x:Name="displayName"
                   VerticalOptions="Center" 
                   HorizontalOptions="Center"
                   Margin="1" 
                   BackgroundColor="Transparent" 
                   BorderColor="Red"
                   Padding="1"
                   AbsoluteLayout.LayoutBounds="0.5,0.5,AutoSize,AutoSize"
                   AbsoluteLayout.LayoutFlags="PositionProportional">
                <StackLayout VerticalOptions="Center">
                    <Label TextColor="Red" HorizontalOptions="Center" Text="This is some text" />
                </StackLayout>
            </Frame>
        </AbsoluteLayout>
    </ContentView.Content>

I then have a "MasterView" that contains the image and the Label view.

 <ContentView.Content>
        <StackLayout>
            <Label Text="Hello Xamarin.Forms!" />
            <AbsoluteLayout>
                <Frame x:Name="masterDisplay"
                   VerticalOptions="FillAndExpand" 
                   HorizontalOptions="FillAndExpand"
                   Margin="1" 
                   BackgroundColor="Transparent" 
                   BorderColor="Blue"
                   Padding="1"
                   AbsoluteLayout.LayoutBounds="0.8,0.5,310,240"
                   AbsoluteLayout.LayoutFlags="PositionProportional">
                    <framePan:PanContainer>
                        <framePan:PanView>
                        </framePan:PanView>
                    </framePan:PanContainer>
                </Frame>

                <Frame x:Name="masterDisplay2"
                   VerticalOptions="FillAndExpand" 
                   HorizontalOptions="FillAndExpand"
                   Margin="1" 
                   BackgroundColor="Transparent" 
                   BorderColor="Blue"
                   Padding="1"
                   AbsoluteLayout.LayoutBounds="0.2,0.5,310,240"
                   AbsoluteLayout.LayoutFlags="PositionProportional">
                    <framePan:PanContainer>
                        <framePan:PanView>
                        </framePan:PanView>
                    </framePan:PanContainer>
                </Frame>
            </AbsoluteLayout>

        </StackLayout>
    </ContentView.Content>

In my demo I am just using a frame with some dimensions where the image would go for simplicity.

I have tried several different ways to cap and move the text within the image and none are quite right. I can get the label to stay within the bounds of the image (frame). But the movement is on the frame not on the Label.

I have done some digging and there is a drag and drop gesture for xamarin forms. This might be a better fit for what I am trying to do however I am unsure. As the action isn't exactly a drag and drop but a move.

I am unsure if there is a way to cap where you can drag and drop to on the screen. My guess is maybe with drag and drop I can drag an item to a new location and then do a transform similar to the pan?

Has anyone tried to do this?
I am unsure if I am looking at the wrong gestures or if what I am doing makes sense.

Many thanks

Can I create an overload of a templated interface?

$
0
0

I'm trying to make a free version of my app. The app saves records to a database, and I have Repository classes for all of the tables of data.
In the free version I want to limit the number of records that can be saved/retrieved. The easiest way I can think of to do this, is to overload the database functions in the instance of the free app.
I need to figure out how to validate the purchased state of my app, then store that flag in the database. If the user requests a refund, I can then verify that and change the flag in the DB to go back to the free version. (these flags could be recorded as blob types and (en/de)crypted at runtime when being loaded)

I could then make an overloaded function that would limit the DB access.

My template declaration looks like this

  public interface IDataBaseRecord<T>
  {
      Task<ObservableCollection<T>> GetItems();
  }

then in the current implementation of my MaintenanceDataRepository.cs

  public class MaintenanceDataRepository : IDataBaseRecord
  {
    public async Task<ObservableCollection<MaintenanceData>> GetItems()
    {
        CreateConnection();
        return new ObservableCollection<MaintenanceData>(await connection.Table<MaintenanceData>().ToListAsync());
    }
  }

For instance I could make the following GetItems() overloaded function.

  public overload ObservableCollection<MaintenanceData> GetItems()
  {
    ObservableCollection<MaintenanceData> returnData = new ObservableCollection<MaintenanceData>();
    var items =  new ObservableCollection<MaintenanceData>(await connection.Table<MaintenanceData>().ToListAsync());

    for (var i = 0; i < _FreeResults_ ; i++)
    {
      if(items[i] != null)
          returnData.Add(items[i]);
      else
          break;
    }

    return returnData;
  }

But, I have about 15 different data classes I would need to do this to...

Is there a way I can implement the above code as an overloaded function that get's called instead of the automatic GetItems()? I would need to make it conditional, since there are some tables that specify things like manufacturers so I want all of those records to be called, but want to limit the number of records that a regular call can get.
I would then be able to store info in the database, such as number of RewardVideos they've watched and change the number of records based on that, and so on.

Cheers!

RadioButton Checked Color in Xamarin 5.0

$
0
0

I am using the render below for changing radiobutton's circle color.

```

public class MyRenderer2 : RadioButtonRenderer
{
    public MyRenderer2(Context context) : base(context)
    {

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

        if (Control != null)
        {
            Control.ButtonTintList = ColorStateList.ValueOf(Android.Graphics.Color.ForestGreen);
        }
    }
}

```

In xamarin 4.8 it worked perfectly. In Xamarin 5.0 it doesnt. Is there any solution? Thank you

How to make a horizontally centered Entry expand to be just wide enough to show it's entire Text ?

$
0
0

How can one reliably implement a horizontally centered Entry that expands to the width required to show its Text, without expanding beyond that?
(I want a readonly Entry of the minimum width that shows its entire Text, where the readonly Entry is centered horizontally on the page).

Some code that demonstrates an Entry with HorizontalOptions = CenterAndExpand but where the Entry does not expand to show its entire Text can be found at https://xamarin.github.io/bugzilla-archives/59/59391/bug.html

TBH, I do have a hacky workaround, that involves using a Grid to overlay the Entry on a Label that has its Text property bound to the same property on the ViewModel as the Entry, but that's hacky as I have to apply a Margin to the Label using some magic numbers. In that hacky workaround, the Label expands to show the entire Text, resulting in the Grid expanding, resulting in the Entry also expanding. I'd rather have a solution that doesn't involve magic numbers.

Real Modal Dialog with PRISM & RG.PopUp

$
0
0

I would like to achieve a functionality like an DisplayAlert with PRISM and RG.PopUp
PRISM and RG.PopUps works fine together and I know how to deal with NavigatedFrom, NavigatedTo and MessagingCenter to pass Answers back to my ViewModel. But I would like to wait for an answer and move forward afterwards, like in a DisplayAlert. I need just True or False.

if (await DialogService.DisplayAlertAsync("Question", "Yes or no ?, "Yes", "No") == false)
     return;

Something like this ( I made that up):

    var result = await NavigationService.NavigateAsync("PopUpYesNo", navigationParams);
    //now wait for PopUp to close
    if (result == true)
    {
    ...
    }

I can't be the first one looking for that, can I? I googled a lot but found nothing...

How can i select multiple files(image, video, audio, pdf, ..) from phone storage ?

$
0
0

I'm developing an app that provide me upload my files to server. I need to select/multi select my files from my phone. Do you know any file picker plugin ?


Tabbed Page Swipe in iOS

$
0
0

I am building a tabbed page by adding 2 content pages as children from C#.

Swipe to navigate between content page 1 and content page 2 only works on Android. Is this how it is supposed to be? If so, how do I implement custom swipe?

How to set cursor color for Entry and Editor when targeting Android

$
0
0

Having just upgraded from XF 4.8 to 5.0, I've had to migrate to using AndroidX. As a result, the piece of code that is found in multiple locations when Googling that allows the cursor color for Xamarin.Forms Entry and Editor Views to be set dynamically no longer works.

Instead, that code (see below) now throws
Java.Lang.NoSuchFieldError: no "I" field "mCursorDrawableRes" in class "Landroid/widget/TextView;" or its superclasses

IntPtr IntPtrTextViewClass = JNIEnv.FindClass(typeof(TextView));
IntPtr mCursorDrawableResProperty = JNIEnv.GetFieldID(IntPtrTextViewClass, "mCursorDrawableRes", "I");

For iOS, Xamarin now provide a SetCursorColor method (see https://docs.microsoft.com/en-us/dotnet/api/xamarin.forms.platformconfiguration.iosspecific.entry.setcursorcolor?view=xamarin-forms ).

How can we dynamically set the cursor color for Entry and Editor on Android when using XF 5.0 ?

Xamarin.Forms.Maps - Get location

$
0
0

I'm using Xamarin.Forms.Maps and everything is working as expected except that I can't figure out how to read map location.
This is insane, I almost read every tutorial but can't find out how!
There is an event called onclicked, I don't want that. I simply have a button where on click I want to read the center location of the map.

UWP Could not find windows runtime 'Microsoft.UI.Xaml.Controls.XamlControlsResources'

$
0
0

Hey all,
I just updated my xamarin forms version from 4.2 to 4.3.

When I try to run my UWP application, I get a splash screen and I get the following exception

$exception {"Could not find Windows Runtime type 'Microsoft.UI.Xaml.Controls.XamlControlsResources'.":"Microsoft.UI.Xaml.Controls.XamlControlsResources"} System.TypeLoadException

in my uwp's app.xaml.cs Xamarin.Forms.Forms.Init(e)
I went through the process of cleaning my solution, reinstalled the nugut packages, and deleting my bin and object folders. Still no luck.

After some research, this is from the Microsoft.UI.Xaml.dll which should be packaged in UWP by default.

Has anyone experience this issue before?

Binding Label without Listview

$
0
0

Hi Techie,

I have an issue to bind an label without Listview .

I want to bind the label without listview how to achieve this ?

Viewing all 76418 articles
Browse latest View live


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