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

IMAGE CROP and RESIZE in Xamarin Forms

$
0
0

Need to implement image resizing and cropping in Xamarin Forms


AlarmManager on IOS

$
0
0

What is the equivalent of AlarmManager on IOS?
What is the difference between Android.Provider.AlarmClock Class and AlarmManager?

TabbedPage Bar change its color on Android

$
0
0

Hi guys!

I am doing an app that requires to set a TabbedPage (with 4 NavigationPage because the customer wants the tabs being visible the whole time) and everything is working fine on iOS, but, on Android, when I select a tab, the Bar (which on Android is an ActionBar) change its color to the default theme color.

I've been doing a lot of research (event customizing the theme's app) still getting this behavior . In fact, this only occurs on Samsung devices (I've tested it on Alcatel's phones and also Nexus 5 phones).

To be more specific, I've tried this combinations navigating between tabs:

  • Tab 1 > Tab 2 = Bar still has the Color I desire
  • Tab 1 > Tab 3 = Bar still has the Color I desire
  • Tab 1 > Tab 4 = Bar still has the Color I desire
  • Tab 1 > Tab 2/3/4 > Tab 3 = Bar change its color to the default's theme color until I come back to Tab 1

I have noticed that every third call to a page changes the color. I have tried to catch some error or something but nothing.

Additional: my TabbedPage calls a custom render to set the icons, even forcing the Tab.TabSelected event to set the background drawable to the action bar, nothing happens.

Somebody has or had this problem with Samsung devices before or maybe an annoying bug.

TabbedPage code

`

public class MainTabbedPage : TabbedPage
{
    public MainTabbedPage ()
    {
        Children.Add (new NavigationPage ( new HomePage () ) {
            BarBackgroundColor = Business.CorporateBlue,
            BarTextColor = Color.White,
            Icon = "ic_home.png"
        });

        Children.Add (new NavigationPage ( new FavoritesPages () ) {
            BarBackgroundColor = Business.CorporateBlue,
            BarTextColor = Color.White,
            Icon = "ic_favorites.png"
        });

        Children.Add (new NavigationPage ( new SearchPage () ) {
            BarBackgroundColor = Business.CorporateBlue,
            BackgroundColor = Business.CorporateBlue,
            BarTextColor = Color.White,
            Icon = "ic_search.png"
        });

        Children.Add (new NavigationPage ( new ContactPage () ) {
            BarBackgroundColor = Business.CorporateBlue,
            BarTextColor = Color.White,
            Icon = "ic_contact.png"
        });

    }

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

    }

    protected override void OnCurrentPageChanged ()
    {
        base.OnCurrentPageChanged ();
        var current = (NavigationPage)this.CurrentPage;
        if (current.CurrentPage.GetType () == typeof(FavoritesPages)) {
            //Do something some day
        } else if (current.CurrentPage.GetType () == typeof(SearchPage)) {
            Device.BeginInvokeOnMainThread (() => ((SearchPage)current.CurrentPage).LoadPromotions ().ConfigureAwait (false));
        }


    }


}

`

CustomRenderer on Android Project
`

    public class CustomTabRenderer: TabbedRenderer
        {
            protected override void OnElementChanged (ElementChangedEventArgs<TabbedPage> e)
            {
                base.OnElementChanged (e);
            }
            public override void OnWindowFocusChanged(bool hasWindowFocus)
            {
                ActionBar actionBar = (Context as Activity).ActionBar;
                if (actionBar.TabCount > 0)
                {
                    foreach( Page page in Element.Children ) {

                        if (page.Icon == null)
                            continue;
                        int index = Element.Children.IndexOf ( page );
                        var tab = actionBar.GetTabAt( index );
                        tab.SetText (string.Empty);
                        tab.TabReselected += (object sender, ActionBar.TabEventArgs e) =>
                            page.Navigation.PopToRootAsync();
                        //Removing the .png because Android be crazy
                        tab.SetIcon (Resources.GetIdentifier (page.Icon.File.Replace(".png", ""), "drawable", Forms.Context.PackageName));

                    }
                }
                base.OnWindowFocusChanged(hasWindowFocus);
            }
        }

`

EDIT

Seems there somebody has reported this in https://bugzilla.xamarin.com/show_bug.cgi?id=22237

So for the moment I will show an icon in the bar meanwhile I figure out how to solve this "customer-friendly" way.

Regards

Can't use custom font in VS 2015+Xamarin.Forms

$
0
0

Good day. I'm new in Xamarin. Trying to use custom font in Android project. Tried to repeat from tutorial (https://developer.xamarin.com/guides/xamarin-forms/user-interface/text/fonts/), but unsuccessfully. Load 3 projects from GitHub, including same from tutorial. All projects work correctly - custom font in app. When I do the same, using copy-paste, or typing some code - nothing No errors, no warnings - just default font in labels. Checked, as I think, everything - font file is in Assets\font folder (though in WorkingWithFonts tutorial it is in Assets and working), Build Action - AndroidAssets, always copy to output directory, names of font are correct. So I wonder, it's like "Hello world" not working. Can someone say, whet can be wrong here?

Unable to bind a ContextAction menuItem command to the viewModel.

$
0
0

I have a ListView with Textcells and have added TextCell.ContextActions with MenuItems. I have a Delete Menu item and bounf the command to a command in my view model which is hooked up to a method. However, the method is not being hit. Any ideas?

<ListView x:Name="lvNotes" ItemsSource="{Binding Notes}" IsVisible="{Binding PersonNotesVisible}" RowHeight="70">
            <ListView.ItemTemplate>
                <DataTemplate>
                        <TextCell Text="{Binding Title}" Detail="{Binding DateAdded}">
                            <TextCell.ContextActions>
                                <MenuItem Text="Share"/>
                                <MenuItem  Command="{Binding DeleteNoteCommand}" CommandParameter="{Binding .}" Text="Delete" IsDestructive="True" />
                            </TextCell.ContextActions>
                        </TextCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

In the VIEWMODEL, I have initiated the DeleteNoteCommand in the VM constructor

public ICommand DeleteNoteCommand { get; set; }
DeleteNoteCommand = new Command(DeleteAction);

    private void DeleteAction(object obj)
        {

        }

Layout is shifted down on iOS back gesture if navigation bar of underneath page is hidden

GREF ListView and PopToRootAsync (Xamarin Forms 2.3.3.180 targeting Android)

$
0
0

Hi,

I am asking for your help as I am new to Xamarin but not to .NET. I am working on a wizard like project based on a lot ListView(s) which are leaking GREF. (JNI Global REFerences)
As some of you probably know, the GREF limit of the Xamarin emulator is 2000 references. If there is a leak this could become a problem really quickly.

To investigate this, I have enabled GREF tracking on my emulator and created a new shared Forms solution to keep things simple. The solution contains only one form with a ListView and several buttons for tests. The first button reloads another instance of the (same) page with a populated ListView (3 items). If I click on it, I can see the GREF increase in the output windows in Visual Studio. Then I also have one button to call the garbage collector and the others are button to pop pages in different ways.

This is becoming ugly now, when I load several instance (of the page) and the call PopToRootAsync without animation (a Xamarin Method), the GREF never decrease. If I use the garbage collector multiple times (button Clean IT), it doesn't decrease. It I go drink a coffee and comeback and call the GC, it doesn't decrease.

This is really a problem and probably a bug. I have done some reseach to find a workaround and tried a lot of (sometime random) things and compared GREF metrics to find this:

  • If the PopAsync is animated, more GREF are released. (why?)
  • If I clear the ObservableCollection before the PopAsync more GREF are released. (proly because items in ListView are released?)
  • If I PopAsync the page from the view itself, a lot more GREF are released. (this one sound like a X-File episode...)

So I created a recursive method in the view to do the same as a PopToRootAsync but on the view:

//Homemade PopToRoot each view pop itself recursively
//must be on the view to work! (I don't know why...)
public async Task PopToRoot(bool animate)
{
    var nav = Application.Current.MainPage.Navigation;
    if (nav.NavigationStack.Count > 1) //Don't touch the root
        if (nav.NavigationStack[nav.NavigationStack.Count - 1].BindingContext is IDisposable) // Clean Collections if ViewModel Is Disposable
            (nav.NavigationStack[nav.NavigationStack.Count - 1].BindingContext as IDisposable).Dispose();

    await nav.PopAsync(animate);

    if (nav.NavigationStack.Count > 1 && nav.NavigationStack[nav.NavigationStack.Count-1] is ListViewPage)
        await (nav.NavigationStack[nav.NavigationStack.Count - 1] as ListViewPage).PopToRoot(animate); //Recursive Pop
}

Using this method released the most GREF. I have run some tests with other methods in my solution:

  • Xamarin PopToRootAsync not animated
  • Xamarin PopToRootAsync animated
  • Recursive PopToRootAsync not animated
  • Recursive PopToRootAsync animated

I have defined a test protocol, but without the call to Dispose (to be able to compare with the Xamarin PopToRootAsync method)

0) Load the App and click on CleanIT several times -> GC.Collect()
1) Write down the current GREF
2) Load the page 3 times
3) Write down the current GREF
4) Use the tested method to PopToRootAsync
5) Click on (CleanIT) -> GC.Collect()
6) Write down the current GREF
7) Click on CleanIT multiple time (until GREF is stabilized)
8) Write down the current GREF
9) Calculate the delta between 8 and 1 (this should be the number of GREF leaked)
10) GOTO 1

The results are:

  • Recursive PopToRootAsync animated: 42 GREFs not released
  • Recursive PopToRootAsync not animated: 156 GREFs not released
  • Xamarin PopToRootAsync animated: 125 GREFs not released
  • Xamarin PopToRootAsync not animated: 185 GREFs not released

If I clean the collection before the Recursive PopToRootAsync animated: 14 GREFs are not released (this is really better than 185 leaked GREFs...)

I have attached the zip file of the solution with this post. Since I am new, I would like to know what you think about it, if you have a better solution to collect all the GREFs and if this should be reported as a bug.

Thanks!

Changing TabbedPage Tab Colors on Android

$
0
0

I cant for the life of me find out how to change the TabbedPage Tab Colors on Forms 1.4+ using an implicit style in code.

I can set the BarBackgroundColor on a NavigationPage but the same options dont exist on TabbedPages.


var navigationPagesStyle = new Style(typeof(NavigationPage)) { Setters = { new Setter { Property = VisualElement.BackgroundColorProperty, Value = NavigationPages.BackgroundColor }, new Setter { Property = NavigationPage.BarBackgroundColorProperty, Value = NavigationPages.BarBackgroundColor }, new Setter { Property = NavigationPage.BarTextColorProperty, Value = NavigationPages.BarTextColor } } }; if (NavigationPages.key == null) { Application.Current.Resources.Add(navigationPagesStyle); } else { Application.Current.Resources.Add(NavigationPages.key, navigationPagesStyle); }

I think I need to know the new Style(typeof(OBJECT)) but I dont know what the proper OBJECT is to put in there.

Anyone have any suggestions? I cant figure out how to change it in a custom renderer either as Android.App.ActionBar.Tab is obsolete now.
Thanks
M


Tabbed Page Tab Colors

$
0
0

Hello Im using Xamrin froms
I have A Tabbed Page and it has "3" ,
I have Three Tabs in the Tabbed page and How can i Change the background Color of the whole three tabs ?

How to get an Image to appear screen width and required height in correct aspect ratio

$
0
0

Hi all,
I am trying to display an image at the top of a page. The image is 700 wide by 140 high, and the source is a url.
My page is defined in code. I created a stack layout and added the Image. It displays in the correct aspect ratio, but it doesn't go full width. I manage to get it to go full width, but the height it is calculating is incorrect and so is trimming the top and bottom off the image. Here is some copy and pasted code:

        var source = new UriImageSource
        {
            Uri = new Uri("http://thisismyimageurl"),
            CachingEnabled = false,
        };

        var img = new Image
        {
            HorizontalOptions = LayoutOptions.FillAndExpand,
            Source = source,
            Aspect = Aspect.AspectFill,
        };

        var layout = new StackLayout()
        {
            Spacing = 0,
            Padding = new Thickness(15, 5, 15, 5),
            HorizontalOptions = LayoutOptions.FillAndExpand,
            Orientation = StackOrientation.Vertical,
            Children =
            {
                img,
                // There will be labels, buttons etc following the image
            }
        };

        Content = layout; // EDIT: Added for completeness of this ContentPage example

I have attempted many variations on the layout options for the image and for the stack layout, nothing I do will make the image full width (within the padding of course), and correct height at the same time.

Any ideas on this?

Thanks
John

Getting runtime AOT unhandle exception when iOS app going to launch in iPhone.

$
0
0

I developed mobile app in Xamarin.forms to create app for Android and iOS system. Project is complied successfully but getting below exception just after launch on mobile.

System.ExecutionEngineException: Attempting to JIT compile method 'AppsFlyer.AppsFlyerTracker:set_IsDebug (bool)' while running with --aot-only. See http://docs.xamarin.com/ios/about/limitations for more information.

App is working fine on Simulator but problem is coming on iPhone. Please help me to resolve this issue. I tried to fix this issue after software upgrade but still same error is coming.

ImageSource binding resets, image disappears after appearing

$
0
0

I have an image control in one of my app implementation using xamarin forms (2.0), which is binded to an ImageSource

XAML Code:

 <Image x:Name="MyPhoto" Grid.Row="0"
         Grid.Column="0"
         Aspect="AspectFit"
         Source="{Binding ImageSource3}"
         VerticalOptions="CenterAndExpand" WidthRequest="125" >
      <Image.GestureRecognizers>
        <TapGestureRecognizer
            Command="{Binding SelectPictureCommand}" />
      </Image.GestureRecognizers>
    </Image>

When, I tap on the image, it opens the photo album to pick a photo (using xam media plugin). I am able to successfully select the picture. The problem is that the image appears for a split of second in the image control and then it disappears. The same code works well in a different form in the same project. Also this works well in android but gives issue in ios . I am testing using iPhone.

ViewModel Code:

        private async Task SelectPicture()
        {

            try
            {
                var file = await CrossMedia.Current.PickPhotoAsync();  //using xam media plugin
                ImageSource3 = ImageSource.FromStream(() =>
                {
                    var stream = file.GetStream();
                    stream.Position = 0;
                    file.Dispose();
                    return stream;
                });

                mediaFilePath = file.Path;
                uploadImage = true;
            }
            catch (System.Exception ex)
            {

            }
        }

Any help would be appreciable!

How can we change color of Progressbar?

$
0
0

This is my code :

< ProgressBar Progress="0.5" WidthRequest="500" HeightRequest="15" HorizontalOptions="StartAndExpand" / >

Try and background, but I want to change the indicator color line progress

Grid : How to set rowspan for a custom control

$
0
0

Hello,

I have a grid control, and I want to set children because I use this control as mainTemplate inside my views.

This is my code :

var imageView = new Image
            {
                Source = "navbar.png",
                HeightRequest = 60,
                Aspect = Aspect.Fill,
            };
            this.Children.Add(imageView, 0, 1, 1, 12);
        }
        //      <Image Source = "navbar.png" Grid.Row="1"
        //        Grid.Column="0" Grid.RowSpan="13"
        //        HeightRequest="60"
        //        Aspect="Fill" />

I want to setup the columnSpan without success.

Could you help me to add it to my childView ?

Regards

Installing SQLite-net-pcl

$
0
0

I am trying to convert my project from SQLite.Net-PCL to sqlite-net-pcl (latest stable version; 1.3.1), as it says on Xamarin's working with databases, but when I install it, it has to install 40 packages (or so) as listed below

Microsoft.NETCore.Platforms 1.0.1
Microsoft.NETCore.Targets 1.0.1
runtime.native.System   4.0.0
SQLitePCLRaw.core 1.1.2
SQLitePCLRaw.bundle_green 1.1.2
System.Collections 4.0.11
System.Collections.Concurrent 4.0.12
System.Diagnostics.Debug 4.0.11
System.Diagnostics.Tools 4.0.1
System.Diagnostics.Tracing 4.1.0
System.Globalization 4.0.11
System.IO 4.1.0
System.IO.Compression 4.1.0
System.Linq 4.1.0
System.Linq.Expressions 4.1.0
System.Net.Http 4.1.0
System.Net.Primitives 4.0.11
System.ObjectModel 4.0.12
System.Reflection 4.1.0
System.Reflection.Extensions 4.0.1
System.Reflection.Primitives 4.0.1
System.Resources.ResourceManager 4.0.1
System.Runtime 4.1.0
System.Runtime.Extensions 4.1.0
System.Runtime.InteropServices 4.1.0
System.Runtime.Numerics 4.0.1
System.Text.Encoding 4.0.11
System.Text.Encoding.Extensions 4.0.11
System.Text.RegularExpressions 4.1.0
System.Threading 4.0.11
System.Runtime.InteropServices.RuntimeInformation 4.0.0
System.Threading.Tasks 4.0.11
System.Xml.ReaderWriter 4.0.11
System.Xml.XDocument 4.0.11
NETStandard.Library 1.6.0
sqlite-net-pcl 1.3.1

I understand that it needs some packages, but it seems like a lot of packages to me.
I am using Xamarin.Forms version 2.3.3.180 (the latest stable)

And if I continue the installation, an error like this occurs

Could not install package 'System.Runtime.InteropServices.RuntimeInformation 4.0.0'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.5,Profile=Profile111', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

How can I install sqlite-net-pcl, so I can continue working with SQLite on Android N?


Slider in a Carousel Page navigation

$
0
0

Hello,
There is a confusion on the events when we touch the screen. Does it concern the Slider or does the message concern the carousel view ?
Thx

Native Android library in cross-platform mobile app

$
0
0

Hi all,

we are developing a mobile application for Android and iOS and we have chosen the Xamarin.Forms platform to create our app in a cross-platform manner. This app shall use external functions provided to us as external library. Currently, this library is available for Android as native Android library (Android Library, written in Java and compiled as .aar file). The external library also includes a sample Android app written in Java as well in order to verify that the library is working and in order to demonstrate the library. The library plus sample app can be opened in Android Studio IDE and can be tested nicely. Soon, our partner will provide an iOS version of this library, probably as native iOS library.

Binding the library as described in https://developer.xamarin.com/guides/android/advanced_topics/binding-a-java-library/binding-an-aar/ works well which means the imported namespace, classes and methods of the library are nicely accessible in our Xamarin project.

Now, we are facing the following problem: It is required that the App class (which is the application instance for the compiled Android app to which all activities refer to and which must be a sub-class of android.app.Application) must inherit 'MyApplication' which is part of the library. In other words, 'MyApplication' extends android.app.Application and implements some interface which is part of the library as well and 'App' (our Android application instance) must extend 'MyApplication'. Otherwise, the library functions do not properly work. But how to make this work in a Xamarin cross-platform application? In our Xamarin cross-platform project, there can be defined a custom application class inheriting from xamarin.forms.application but it is not possible to let this class inherit from 'MyApplication' because latter is Android-only but the cross-platform application class should be platform-independent of course. Otherwise, within the Android project of our solution there is a class MainActivity.cs which calls LoadApplication() to which I can pass a xamarin.forms.application object but how to pass my Android app class extending android.app.Application? Are xamarin.forms.application and android.app.Application somehow convertable? Also, within OnCreate() within the MainActivity.cs, it is possible to get the current application instance (which is in fact of type android.app.Application) but is it possible to set it?

Thank you all very much in advance for some inputs.

Ensure that this project has Microsoft.Bcl.Build installed and packages.config

$
0
0

Does anybody know a solution for this?

Severity Code Description Project File Line Suppression State
Error Could not locate myApp.UWP\packages.config. Ensure that this project has Microsoft.Bcl.Build installed and packages.config is located next to the project file. myApp.UWP

Xamarin Forms Pop Up Form

$
0
0

attached are 3 screenshots from different android apps. how do you go about replicating this in xamarin forms? what are they even called?

thanks,

jas

Kindly assist with solving these errors, NB: Xamarin claims to be installed properly.

$
0
0

Kindly assist with solving these errors,
1. missing extension xamarin.visualstudio
2. install ios.csproj
NB: Xamarin claims to be installed properly.

Viewing all 91519 articles
Browse latest View live


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