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

How to override the method OnBackButtonPressed() to navigate back two pages or more?

$
0
0

I am trying to override the hardware back button to go back two pages. Of course I can not override it with the normal navigation proccess await Navigation.PushAsync(new SomePage()); because it will make the method async which does not match the base method bool return type. any suggestions??


Navigation in Maps possible in XF?

$
0
0

Hi,
I want to create a mobile app using Xamarin.Forms, is it possible to set map navigation in it. Live example is UBER. Once we set pickup and destination it will navigate us to the destination. I want something like that , is it possible to achieve it in XF.

Deploying to android emulator error:Could not load assembly 'System.Runtime.CompilerServices.Unsafe'

$
0
0

When trying to deploy Xamarin.Forms to android emulator the following message is displayed in VS2017 output window.

07-27 10:31:25.512 D/Mono ( 3680): Assembly Loader probing location: 'System.Runtime.CompilerServices.Unsafe'.
07-27 10:31:25.512 F/monodroid-assembly( 3680): Could not load assembly 'System.Runtime.CompilerServices.Unsafe' during startup registration.
07-27 10:31:25.512 F/monodroid-assembly( 3680): This might be due to an invalid debug installation.
07-27 10:31:25.512 F/monodroid-assembly( 3680): A common cause is to 'adb install' the app directly instead of doing from the IDE.

Initially the application could be deployed without any problems to the android emulator.
The last change that I did was adding a custom WebViewRender. Could the fail of the application deployment be related to that ?

HasUnevenRows not working for 2 nested listviews

$
0
0

In my application , i have 3 nested listviews in Xamarin forms , and when one cell is clicked it should expand the cell and show the data. The data i has been binded successfully , and the list is populated. The First 2 level listviews works as expected (The row expands and shows the child listview).But when 3rd listview expands the first level listview doesn't expand dynamically according to new content.
If anyone knows the solution to dynamically resize the content in listview , please share here.

Thanks in advance

Bug or Feature? Resuming App Fires OnAppearing for All Pages in MasterDetail Detail's Nav Stack

$
0
0

Hi there,

I'm running into an odd sequence of events when I navigate within the Detail of a MasterDetail layout, sleep/resume my application, then pop the Detail's navigation stack to root. I'm hoping someone can offer some insight into whether Xamarin Forms is supposed to do this, and possible workarounds so I can get the behavior I want.

Background

I'm creating a data entry app with Xamarin Forms, using a MasterDetail layout to switch between workflows. On startup, the Detail is set to a ContentPage (we'll call it "PageOne") wrapped in a NavigationPage. The OnAppearing() method on that ContentPage loads data into a list on the page, with the intent of refreshing the data whenever the page is made visible to the user.

From that page, the user navigates through a series of pages (PageOne -> PageTwo -> PageThree) via the Detail NavigationPage, not by selecting a new Detail from the Master page. (No navigation to a new Detail goes on here.) Some data entry is done by the user taking a picture, for which I'm using James Montemagno's Media plugin. Switching to the camera is considered leaving the application, setting off the App's OnSleep() method. OnResume() is fired when a picture is taken. and control returns to the app.

What The..

Here's where things get weird: when the app resumes, the OnAppearing() method fires for every page currently part of the MasterDetail Detail's NavigationPage stack. But at this point, PageOne isn't actually visible. It only becomes visible after the user presses a submit button that saves the data to the local database, whereupon PopToRoot is called - but OnAppearing() isn't called again, so the most recent state of the data isn't displayed.

Repro

I've attached a solution that reproduces the bug in basic form in Xamarin Forms 2.3.4.231.

App Structure

MainPage = MasterDetailPage

  • Master = MasterPage
  • Detail = NavigationPage(root = PageOne)

Actual Behavior

The following sequence of steps calls the following methods:

1: Start app
Application: OnStart()
PageOne: OnAppearing()

2: Navigate to PageTwo (In the attached repro project: TO PAGE TWO button)
PageOne: OnDisappearing()
PageTwo: OnAppearing()

3: Navigate to PageThree (In repro: TO PAGE THREE button)
PageTwo: OnDisappearing()
PageThree: OnAppearing()

4: Leave app (Running apps list button. I'm running this on a Marshmallow emulator, so it's the rightmost (square) one.)
PageThree: OnDisappearing()
Application: OnSleep()

5: Return to app
Application: OnResume()
PageThree: OnAppearing()
PageOne: OnAppearing()
PageTwo: OnAppearing()

6: Pop Detail to Root (In repro: POP TO ROOT button)
Nothing!

Expected Behavior

Meanwhile here's what I need to have happen for my data to refresh itself correctly. This does happen when my app's MainPage is the NavigationPage. The above behavior occurs when I wrap it in a MasterDetail.

1: Start app
Application: OnStart()
PageOne: OnAppearing()

2: Navigate to PageTwo
PageOne: OnDisappearing()
PageTwo: OnAppearing()

3: Navigate to PageThree
PageTwo: OnDisappearing()
PageThree: OnAppearing()

4: Leave app
PageThree: OnDisappearing()
Application: OnSleep()

5: Return to app
Application: OnResume()
PageThree: OnAppearing()

6: Pop Detail to Root
PageThree: OnDisappearing()
PageOne: OnAppearing()

The Ask

My understanding is that loading/refreshing your data in a page's OnAppearing() method is acceptable practice. If I'm mistaken, I'm looking for advice about the right way to go about what I'm trying to do. If I'm not, I'd like to know if this behavior is what Xamarin Forms is supposed to do, and suggestions for how to achieve the behavior I want.

Thanks for reading!

How to get hamburger menu and navigation page at the same time?

$
0
0

Hi there

I'm trying to have a master detail page for my menu, and navigation page to display the hamburger icon, the only thing is if I navigate around detail page, it brings up only arrow. I need to have both. Is there a way to achieve this? I've seen syncfusions and telerik's side drawers but it seems that they do not use navigation page instead they have their own top bar, is there a way to make it all work?

IS there a way to add additional icons to the left side of navigation panel so that I can have back arrow and a hamburger icon or any other icon ?

pic:

Thanks

Multiline text in a ListView (text cut off at the end)

$
0
0

I've see this topic a few times but right now when I need it, I can't find it... I have a problem with a few ListView's in my app. The ListViews are displaying content from a database and from a webservice. The content of the ListView can be very large and sometimes, the text is cut off...

This is my ListView so far:

<ListView Grid.Row="1" x:Name="DataListView" ItemsSource="{Binding GroupData}" GroupShortNameBinding="{Binding ShortCategory}" CachingStrategy="RecycleElement"
            IsGroupingEnabled="True" HasUnevenRows="True" BackgroundColor="#b99f65" SeparatorColor="#55492e" ItemTapped="ListView_OnItemTapped" Margin="0,3,0,0">
    <ListView.GroupHeaderTemplate>
        <DataTemplate>
            <ViewCell>
                <Grid BackgroundColor="#120305" Margin="0">
                    <StackLayout Orientation="Horizontal" VerticalOptions="Center" Margin="15,0">
                        <Label Text="{Binding Category}" TextColor="#b99f65" FontSize="18" FontAttributes="Bold" />
                        <Label Text="{Binding ShortCategory, StringFormat='({0})'}" FontSize="18" TextColor="#b99f65" />
                    </StackLayout>
                </Grid>
            </ViewCell>
        </DataTemplate>
    </ListView.GroupHeaderTemplate>

    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <StackLayout Orientation="Vertical" Margin="10,5" VerticalOptions="Fill">
                    <Label Text="{Binding Name}" FontSize="14" FontAttributes="Bold" Margin="0" />

                    <Label Text="{Binding Effect}" FontSize="11" LineBreakMode="WordWrap" Margin="0" />
                    <Label Text="{Binding Ingredients, StringFormat='Ingredients: {0}'}" FontSize="11" LineBreakMode="WordWrap" Margin="0,3,0,0" SizeChanged="OnLabelSizeChanged" />
                </StackLayout>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

Here, the Ingredients are cut off in iOS on some device sizes. I have implemented a SizeChanged-Event for the last Label to see if the size is set correctly, and it is. This is the output:

[0:] LABEL HEIGHT CHANGED:: 26.5
[0:] LABEL HEIGHT CHANGED:: 26.5
[0:] LABEL HEIGHT CHANGED:: 13.5
[0:] LABEL HEIGHT CHANGED:: 13.5
[0:] LABEL HEIGHT CHANGED:: 26.5
[0:] LABEL HEIGHT CHANGED:: 13.5
[0:] LABEL HEIGHT CHANGED:: 26.5
[0:] LABEL HEIGHT CHANGED:: 13.5
[0:] LABEL HEIGHT CHANGED:: 26.5
[0:] LABEL HEIGHT CHANGED:: 13.5

Any of the "26.5" height labels are cut off in half. Because this only happens on iOS it must be a problem there. Can someone help me out to fix this? I have the same issue on other places of my App too and haven't found a working solution yet... I know I can set the RowHeight to the max possible value but for this I need to know how many times the text will be wraped and it is not a nice solution... I would like to use the dynamic sizing...

Can not build anymore error CS0006 metadata file could not be found

$
0
0

Hi,
one build run of my Xamarin.Forms project was hangging and i had to close VS2017 with task manager.
From this time on I can not build my project anymore...

Iam getting the Error: CS0006 Metadata file 'C:\Projects\MyApp\MyApp\bin\Debug\MyApp.dll' could not be found
MyApp.UWP CSC 1 Active

And the same for the iOS project...

What Ive tried:

  • Windows and VS reboot
  • Project unload in VS
  • Clean every project and rebuild
  • Uninstall and back Install Xamarin.Forms NuGET
  • Delete all "bin" and "obj" folders and "packages.config" files

Please help me with this, Ive no Idea how I can fix this :(


Custom TextOn, TextOff for Switch - possible to override or support on roadmap?

$
0
0

Doing prototyping using Forms 1.3.0.0 (going decent sofar, might turn it into something real) and came upon the Switch component.

In Android this component this has a On/Off text rendered over the switch. In WP and iOS there is no text.

I in the documentation that using the component directly in Android-solution one can set textOn/textOff: http://developer.xamarin.com/guides/android/user_interface/intro_to_switches/

Is there any way to do this using the components supplied for Forms or is there a plan to support this on the roadmap?

My need is a basic True/False usage and would be alright with having no text at all - but a On/Off becomes completely contextually wrong.

How to access dynamically created UI element ?

$
0
0

I am creating UI element and adding to stack layout like

StackContainer = new StackLayout();
StackContainer.Children.Add(new Entry()
{
Placeholder = "Enter text",
ClassId="2"
});
Content = StackContainer;

The important thing is the count of the element is not fixed.

Now I want to access that element how can I access the element?

Can we Use Shared project Library with PCL Project .

$
0
0

Hello All,
I want to Know That Can we use Shared Project Library with PCL Project In order to get the benefit of compiler directive. so that when ever we need platform specific work we can use the shared else use PCL??

[Xamarin Blog] Triggers in Xamarin.Forms

$
0
0

Read the full article to learn about Triggers in Xamarin.Forms.

Please use this thread to discuss or ask questions.

Outof memory exception while using Image control in Xamarin forms

$
0
0

Hi,

Currently we have custom control same like a carouselview in Xamarin. Forms control. We have faced the out of memory exception while loading high density (size) images from external folder/gallary. We have implemented the same control in native Android and faced the same.

But it has been fixed in sample level like in below :)

ImageView imageView = new ImageView(this);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
Bitmap bitmap = BitmapFactory.decodeFile("/storage/emulated/0/Pictures/Screenshots/imageg1.jpg",bmOptions);
bitmap = Bitmap.createScaledBitmap(bitmap,customControlWidth,customControlHeight,true);
imageView.setImageBitmap(bitmap);

And also setting "android:largeHeap=true" in manifest file.

From that reported issue is not occurred in our control. While testing the same in Xamarin.Forms, we have got the same exception.

Tried things:

  1. Settting "android:largeHeap=true" in manifest file.
  2. In our renderer try to add above mentioned native ImageView renderer with bitmap.
  3. Used "CG.Collect()"
  4. Used objects are disposed.

From that checked with CarouselView in Xamarin.Forms with collection of "Image" control, while moving the items throws "OutOfMemory exception".

It looks strange. Can you please fix the memory leak issue in Xamarin.Forms control.

Regards,
@HemalathaMarikumar

Sharing session between WebView and app

$
0
0

Hi

Is there a way we can share session between WebView and app.

I am logging through WebView using URL, and need to show content page based on success or failure.

Thanks
gsalunkhe

Printing a form

$
0
0

I've been trying for hours to send a form to a printing service for both Android and iOS, something I have absolutely no experience with. I've seen https://forums.xamarin.com/discussion/42417/printing-on-ipad-from-webview which, I thought, sent me on the right path but this prints a WebView control. In my case, I want to print a ContentPage.

As an alternative, I thought of creating a HtmlWebViewSource that would generate the equivalent view of the information I want to print, but again, it doesn't work. My main issue is to go from Xamarin.Forms.WebView to (lets say) Android.Webkit.WebView to access the CreatePrintDocumentAdapter()

In my form, I have:

private void OnPrint()
{
  var WebViewSource = new HtmlWebViewSource()
  {
    Html =
    "<html>" +
    "<body>" +
    "Hello world" +
    "</body>" +
    "</html>"
  };

  var WebView = new WebView() { Source = WebViewSource };
  DependencyService.Get<IPrintService>().Print(WebView);
}

IPrintService is

public interface IPrintService
{
  void Print(WebView webView);
}

and my DependencyService is

[assembly: Dependency(typeof(PrintService))]
namespace Whatever.ApplicationLayer.Droid
{
  public class PrintService : IPrintService
  {
    public void Print(WebView webView)
    {
      var PrintManager = (PrintManager)Forms.Context.GetSystemService(Context.PrintService);
      var AndroidWebView = (Android.Webkit.WebView)webView.On<Xamarin.Forms.PlatformConfiguration.Android>();
      var JobName = "Test";
      PrintManager.Print(JobName, AndroidWebView.CreatePrintDocumentAdapter(JobName), null);
    }
  }
}

When it's time to cast webView, it dies ("System.InvalidCastException: Specified cast is not valid.") What am I doing wrong? What am I missing?


Application is crashed due to Xamarin.CarouselView in xamarin android project.

$
0
0

Hi everyone, I have very tied to find out the reason of unexpectedly closing of my xamarin android project. I have used CarouselView in xaml page. When I am navigate to that page application is crashed unexpectedly but it works fine when I run ios project. Actually I am working on portable project. Can you please suggest any idea of this issue. I have posted the my hockeyapp crash report. I think it will help to identify, what the exact cause.Thanks in advance.

Here is hockey app crash report

How to fix and expand stack Layout's height accordingly listview

$
0
0

hello guys, I am new on xamarin.forms I am trying to make a expandable dynamic list which is used inside another xaml page and that xaml page is using scroll view whenever accordion views items expands the rest items of list get disappears stacklayout not fitted themselves accordingly view height please solve this guys... Thanks in advance

ListView Item not updateing correctly on UWP

$
0
0

Hi,

Ive a ListView with ViewCell which contains a Label and a Button, my List is for showing Todo Items and the Button is to mark the Todo Item done and show the status on the Button as Text (with a Unicode Checkmark or Cross).
So I want to change the Button Text when a bool attribute binded to a DataTrigger raises PropertyChaged.

My Model Class "TodoItem" implements the IPropertyChanged interface and my "TodoItemViewModel" has a OberservableCollection with TodoItems and implements the IPropertyChanged interface too ( Iam using the NuGet package "PropertyChanged.Fody" to implement the interface).

For Android and iOS its working perfectly, when Iam clicking the Button of a ListView Item, the "done" Attribute of the TodoItem in the OberservableCollection gets changed to "true" and so the PropertyChaged Event gets triggert and causes the Button DataTrigger in XAML to correctly update the Text of the clicked Button.

But on UWP the Button Text sometimes seems to do not update correctly and gets Empty (normally it sould show a Checkmark or a Cross).

Here is my XAML snippet:

<ListView x:Name="listView" ItemsSource="{Binding TodoItems}" HasUnevenRows="true" Margin="5">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <StackLayout Orientation="Horizontal" BackgroundColor="LightGray">
                            <Label  Text="{Binding name}"  FontSize="Large" FontAttributes="Bold" HorizontalOptions="CenterAndExpand"/>

                            <Button Clicked="doneButton_Clicked" CommandParameter="{Binding .}" HorizontalOptions="End" >
                                <Button.Triggers>
                                    <DataTrigger  TargetType="Button" Binding="{Binding done}" Value="true">
                                        <Setter Property="Text" Value="&#x2714;"/>
                                    </DataTrigger>
                                    <DataTrigger TargetType="Button" Binding="{Binding done}" Value="false">
                                        <Setter Property="Text" Value="&#x2716;"/>
                                    </DataTrigger>
                                </Button.Triggers>
                            </Button>

                        </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
</ListView>

Here is the TodoItemViewModel which is binded as BindingContext in "OnAppearing" method in the CodeBehind of the XAML :

[AddINotifyPropertyChangedInterface]  //From NuGet PropertyChanged.Fody
    public class TodoItemViewModel
    {

        public ObservableCollection<TodoItem> TodoItems { get; set; } //Binded to ListView.ItemsSource

        public TodoItemModel()
        {
        }
    }

Here ist the method for Button Clicked:

private async void doneButton_Clicked(object sender, EventArgs e)
        {
            Button btn = sender as Button;
            TodoItem todoItem= btn.CommandParameter as TodoItem;

            if (todoItem != null && btn != null && btn.IsEnabled && btn.IsVisible)
            {
                if (!todoItem.done)
                {
                    todoItem.done = true;
                }
                else
                {
                    todoItem.done = false;
                }
                await database.Add(todoItem);
            }
        }

Here is a screenshot of the ListView on UWP (Problem marked with blue circle):

I hope someone can help me with this annoying problem on UWP...

Thanks!

Regards,

Tom

Store Data in Firebase Database

$
0
0

Hi, I'm trying to store User's data in the Firebase Database. I add to the project this API https://github.com/rlamasb/Firebase.Xamarin .
There is a better options? I can't use .WithAuth parameter and i don't know why. This is my code:

 var firebase = new FirebaseClient(URLDATABASE);
                            var item = await firebase
                                .Child(string.Format("USER_TABLE/{0}/",user.ID))
                                .PostAsync(user);

I need store a class into the Database if possible, so if you can suggest me a similar option. Now i can't use database because i need pass the auth token.

Local Notification dosen't work

$
0
0

I have followed xamarin documentation guide but in this expression Notification.Builder builder = new Notification.Builder(this), word "this" got red underline
and shows this error:

Argument 1: cannot convert from 'Test.Droid.NotificationService' to 'Android.Content.Context'

My code:
MainPage.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace Test
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();
           DependencyService.Get<ILocalNotification>().LocalNotification();
        }
    }
}

Interface:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

    namespace Test
    {
        public interface ILocalNotification
        {
            void LocalNotification();
        }
    }

Notification class Android:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;

namespace Test.Droid
{
    public class NotificationService : ILocalNotification
    {
        public void LocalNotification()
        {
            Notification.Builder builder = new Notification.Builder(this)
            .SetContentTitle("Sample Notification")
            .SetContentText("Hello World! This is my first notification!")
            .SetSmallIcon(Resource.Drawable.ic_notification);

            // Build the notification:
            Notification notification = builder.Build();

            // Get the notification manager:
            NotificationManager notificationManager =
                GetSystemService(Context.NotificationService) as NotificationManager;

            // Publish the notification:
            const int notificationId = 0;
            notificationManager.Notify(notificationId, notification);
        }
    }
}

Can you please tell me what is wrong?

Thank you.

Viewing all 91519 articles
Browse latest View live


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