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

RequestPermissions does not show dialog

$
0
0

Hi

I have been searching for a while now but have not found a solution yet.
I need to request the READ_PHONE_STATE permission.
I have implemented a device specific implementation of my PCL interface IDeviceSettings.

public void RequestPermissions()
{
try
{
if (Android.Support.V4.Content.ContextCompat.CheckSelfPermission(Forms.Context, Manifest.Permission.Camera) != (int)Permission.Granted)
{
ActivityCompat.RequestPermissions((Activity)Forms.Context, new String[] { Manifest.Permission.ReadPhoneState }, 0);
}
else
{
// Permission has already been accepted previously
}
}
catch (Exception ex)
{
int x = 1 + 1;
}
}

I also implemented the device specific override to check if a permission was granted or not.

public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults)
{
switch (requestCode)
{
case 0:
{
if (grantResults[0] == Permission.Granted)
{
//Permission granted
int x = 1 + 1;

                    }
                    else
                    {
                        //Permission Denied :(
                        //Disabling location functionality
                        int x = 1 + 1;
                    }
                }
                break;
        }
    }

I then call this from my codebehind xaml view (for quick testing).

private async void Button_Clicked(object sender, EventArgs e)
{
IDeviceSettings deviceSettings = DependencyService.Get();
bool enabled = deviceSettings.AutomaticTimeEnabled();
await DisplayAlert("Output", enabled.ToString(), "OK");

        deviceSettings.RequestPermissions();

        //string hwid = deviceSettings.GetHardwareId();
        //await DisplayAlert("Output", hwid, "OK");
    }

Now i dont get a dialog where i can accept the requested permissions, but the override in MainActivity gets called immediately with Permissions denied.
I also tried launching an activity from android and requesting them there but then i dont even get the callback.

Some more info :

Visual Studio 2017 Community

Minimum Android Version : 4.1 (16)
Target Android Version : 7.1 (25)

Xamarin 4.5.0.486 (fec6f88)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android SDK 7.3.1.2 (9dbc4c5)
Xamarin.Android Reference Assemblies and MSBuild support.

Xamarin.iOS and Xamarin.Mac SDK 10.10.0.37 (ad35de4)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

Using the Plugin.Permissions from James is not an option since it breaks my app, issue can be found here :
https://github.com/jamesmontemagno/PermissionsPlugin/issues/57#issuecomment-318839270

Any help = greatly appreciated.


DisplayAlert not working

$
0
0

Dears,

I am using DisplayAlert in my project for displaying no internet connection alert. Unfortunately, it is not working.

It working fine in another part. I don't know the reason why it behaves like this.

My code:

               if (Utility.IsInternet())
                {
                    UserTweetsList();
                }
                else
                {
                    Debug.WriteLine("Enter no internet block");
                    DisplayAlert("Alert", "No internet connection", "Ok");
                }

Code enters the else block and prints the "Enter no internet block" in the output, but not displaying the alert message.

What are the possible reasons for this?

Thanks in advance....

No property, bindable property, or event found when using VisualElement.Scale

$
0
0

I'm having an issue whne using the VisualElement.Scale on XAML,

This is the code i used:

<ActivityIndicator x:Name="Indicator"
                   VerticalOptions="CenterAndExpand"
                   IsVisible="True"
                   IsRunning="True"
                   Color="White"
                   HorizontalOptions="Center"
                   >
    <ActivityIndicator.Scale>
        <OnPlatform x:TypeArguments="x:Double" iOS="2"/>
    </ActivityIndicator.Scale>
</ActivityIndicator>

And this is the error:
No property, bindable property, or event foundfor 'Scale', or mismatching type between value and property.

The weird is if i changed it into:

<ActivityIndicator x:Name="Indicator"
                   VerticalOptions="CenterAndExpand"
                   IsVisible="True"
                   IsRunning="True"
                   Color="White"
                   HorizontalOptions="Center"
                   >
  5
</ActivityIndicator>

It will work, but not for the OnPlatform.
One more important thing is my forms project is using NETStandard 2.0, Xamarin version 2.4.091020.

When i switch back to a project that use PCL259, Version 2.3.270, it will work but not for the NETStandard 2.0?

Cheers :0

Setting custom marker image would overlay default marker icon along with custom icon

$
0
0

Hello there,
After updating version of forms to 2.4.0.282, I started getting this weird behavior in mapview. I have created a custom renderer for map in android where I am setting marker images as per my requirement. Custom markers in fact appear, but on top of it, it's default icon still gets overlaid.

Note that I am using Xamarin.Maps version 2.4.0.282, tried to downgrade to prior versions as well but I am of no help.

I even tried it out by commenting line, Forms.SetFlags("FastRenderers_Experimental");, but even this didn't help.

Below is code snippet used for setting custom markers,

var pinImage = Resources.GetIdentifier(pin.PinImage.ToLower(), "drawable", Context.PackageName);
var markerImg = BitmapDescriptorFactory.FromResource(pinImage);

map.AddMarker(new MarkerOptions().SetTitle(pin.Pin.Label).SetSnippet(pin.Id).SetPosition(new LatLng(pin.Pin.Position.Latitude, pin.Pin.Position.Longitude)).SetIcon(markerImg));

Layout compression slowing down pages

$
0
0

Hello Folks,
today i tried the new layout compression feature, the results are quite disappointing.

In my last project, i have some complex view (lots of labels, stacklayout, grids, ecc...). They are working fine in IOS but i wanted to see if i can get more improvements. So i decided to add the magic CompressedLayout.IsHeadless=”true” to every layout without gestures, backgrounds etc...

Long story short: Now the pages are appearing waaay slower than before.

Before the change, when i navigated to a page, the content was immediately visible on screen. After enabling CompressedLayout, when i navigate to a page i see the background for like 2-3 seconds, then the content became visible.
The difference is very noticeable whitout measuring things in code or using inspectors.

Anyone noticed something similar? Its seem very odds to me... Any suggestion?

If you guys wants to try out this feature, use complex views, with lots of layouts to compress.

For now i switched back to my normal development without using CompressedLayout, maybe in future i'll do more tests.

Gradient background: what do you think?

$
0
0

Hi guys,
this is an open question. A client wants an app for iOS and Android and all ContentPage with a gradient background. I'm considering to create the gradient dynamically. I saw this post in this forum for iOS (I have to discover how I can implement that in Android).

By the way, I'm worried about the performance. The minimum AndroidOS is 4.x and I think there are devices with different sizes and processors: render a background costs, I think, a lot of resources and the app could be crashed or seems too slow.

Do you have any advice? Has someone experience on that? Thank you in advance.

Cross Platform splash screen

$
0
0

Hello I am pretty new to Xamarin and I want to know how can I achieve this in 3 platforms, Using Titanium Appcelerator I was able to create a new window or View before starting the application and use a cycle to show the Splash Screen, Do I need a view or a window also? Do I have to use XAMP or can i use C# code to achieve this? or o I have to code the splash screen for every platform? like this tutorial here? http://developer.xamarin.com/Guides/Android/User_Interface/Creating_a_Splash_Screen/

Scrolview in view

$
0
0

Hello everyone, I have a question, I have tried to add a scrollview to my XAML page, works well in a vertical way, but when placing my horizontal device the scroll that works is the main screen, not my object listview, I have the following code:

<?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:xfRutero;assembly=xfRutero" x:Class="xfRutero.XamlPage.xamlPedido" x:Name="xamlPedido" BackgroundColor="#F5F5F5"> <StackLayout> <!--Encabezado Pagina--> <StackLayout BackgroundColor="LightSkyBlue"> <StackLayout Orientation="Horizontal"> <Button x:Name="btnScan" Image="scanner.png" BackgroundColor="GreenYellow" WidthRequest="40" BorderRadius="10" HorizontalOptions="StartAndExpand"/> <Label Text="PEDIDOS" TextColor="Black" HorizontalOptions="CenterAndExpand" FontAttributes="Bold"/> <Button x:Name ="btnHome" Text="H" TextColor="Black" BackgroundColor="Red" WidthRequest="40" BorderRadius="10" HorizontalOptions="EndAndExpand"/> </StackLayout> <StackLayout Orientation="Horizontal" HeightRequest="1" BackgroundColor="Black"> </StackLayout> </StackLayout> <!--Datos de la pagina--> <ScrollView> <StackLayout VerticalOptions="CenterAndExpand"> <!--Boton Consulta/Caja texto Articulo/Caja texto Cant. Ante/Caja texto Cant. Actu/Combobox Unidad/Boton Agregar--> <StackLayout Orientation="Horizontal"> <Button x:Name ="btnConsulta" Text="?" TextColor="Black" BackgroundColor="Yellow" WidthRequest="40" BorderRadius="10"/> <Entry x:Name="txtArticulo" FontSize="12" TextColor="Black" Placeholder="Cód.Articulo" HorizontalOptions="FillAndExpand" BackgroundColor="#48D1CC"/> <Entry x:Name="txtCantidadAnte" TextColor="Navy" Placeholder="Ante." BackgroundColor="White" IsEnabled="False"/> <local:MyEntry x:Name="txtCantidad" TextColor="Black" Placeholder="Actu." BackgroundColor="#48D1CC" Keyboard="Numeric"/> <Picker x:Name="pckUnidad" Title ="U" WidthRequest="40" BackgroundColor="#48D1CC" HeightRequest="39"/> <Button x:Name ="btnAgregar" Text="✔" TextColor="Black" BackgroundColor="#33ff4b" WidthRequest="40" BorderRadius="10"/> </StackLayout> <!--Label Nombre Articulo--> <Label x:Name ="lblDescripcion" TextColor="Black" Font="16" BackgroundColor="#48D1CC" HorizontalOptions="FillAndExpand"/> <!--Label Encabezado Precio Sugerido/Label Encabezado Impuesto/Laber Encabezado Precio Venta--> <StackLayout Orientation="Horizontal"> <Label Text="Pre.Sugerido" Font="16" TextColor="Black" HorizontalOptions="StartAndExpand" FontAttributes="Bold"/> <Label Text="I.V" Font="16" TextColor="Black" HorizontalOptions="CenterAndExpand" FontAttributes="Bold"/> <Label Text="Pre.Venta" Font="16" TextColor="Black" HorizontalOptions="EndAndExpand" FontAttributes="Bold"/> </StackLayout> <StackLayout Orientation="Horizontal"> <Label x:Name="lblMonDesCateg" IsVisible="False"/> <Label x:Name="lblMonDescuento" IsVisible="False"/> <Label x:Name="lblPreSuger" Text=" 0.00" Font="16" TextColor="Black" XAlign="End" HorizontalOptions="StartAndExpand" FontAttributes="Bold" BackgroundColor="#48D1CC"/> <Label x:Name="lblIv" Text=" " Font="16" TextColor="Black" HorizontalOptions="CenterAndExpand" FontAttributes="Bold" BackgroundColor="#48D1CC"/> <Label x:Name="lblPreVenta" Text=" 0.00" Font="16" TextColor="Black" XAlign="End" HorizontalOptions="EndAndExpand" FontAttributes="Bold" BackgroundColor="#48D1CC"/> </StackLayout> <!--Linea de division--> <StackLayout Orientation="Horizontal" HeightRequest="1" WidthRequest="320" BackgroundColor="Black"> </StackLayout> <!--Labels Encabezado Lista--> <StackLayout Orientation="Horizontal"> <Label Text="Articulo" TextColor="Black" Margin="5,5,130,5" FontSize="Small" HorizontalOptions="StartAndExpand"/> <Label Text="Anterior" TextColor="Black" Margin="5,5,5,5" FontSize="Small" HorizontalOptions="CenterAndExpand"/> <Label Text="Actual" TextColor="Black" Margin="5,5,5,5" FontSize="Small" HorizontalOptions="EndAndExpand"/> </StackLayout> </StackLayout> </ScrollView> <!--Lista de articulos--> <StackLayout Orientation="Horizontal"> <ListView x:Name="listView" ItemsSource="{Binding lstArticulo}" BackgroundColor="#48D1CC" RowHeight="30" HeightRequest="200"> <ListView.ItemTemplate> <DataTemplate> <ViewCell> <StackLayout Orientation="Horizontal"> <Label Text="{Binding Descripcion}" TextColor="Black" WidthRequest="250" Margin="5" FontSize="Small" HorizontalOptions="StartAndExpand"/> <Label Text="{Binding CantComprada}" TextColor="Black" WidthRequest="40" Margin="5" FontSize="Small" HorizontalOptions="CenterAndExpand"/> <Label Text="{Binding Cant}" TextColor="Black" WidthRequest="40" Margin="5" FontSize="Small" HorizontalOptions="EndAndExpand"/> </StackLayout> </ViewCell> </DataTemplate> </ListView.ItemTemplate> </ListView> </StackLayout> <ScrollView> <StackLayout VerticalOptions="CenterAndExpand"> <StackLayout Orientation="Horizontal"> <Label Text="Subtotal" Font="16" TextColor="Black" HorizontalOptions="StartAndExpand" FontAttributes="Bold"/> <Label Text="Descuento" Font="16" TextColor="Black" HorizontalOptions="CenterAndExpand" FontAttributes="Bold"/> <Label Text="Impuestos" Font="16" TextColor="Black" HorizontalOptions="CenterAndExpand" FontAttributes="Bold"/> <Label Text="Total" Font="16" TextColor="Black" HorizontalOptions="EndAndExpand" FontAttributes="Bold"/> </StackLayout> <StackLayout Orientation="Horizontal"> <Label x:Name="lblSubtotal" Text=" 0.00" Font="16" TextColor="Black" XAlign="End" HorizontalOptions="StartAndExpand" FontAttributes="Bold" BackgroundColor="#48D1CC"/> <Label x:Name="lblDescuento" Text=" 0.00" Font="16" TextColor="Black" HorizontalOptions="CenterAndExpand" FontAttributes="Bold" BackgroundColor="#48D1CC"/> <Label x:Name="lblImpuestos" Text=" 0.00" Font="16" TextColor="Black" HorizontalOptions="CenterAndExpand" FontAttributes="Bold" BackgroundColor="#48D1CC"/> <Label x:Name="lblTotal" Text=" 0.00" Font="16" TextColor="Black" XAlign="End" HorizontalOptions="EndAndExpand" FontAttributes="Bold" BackgroundColor="#48D1CC"/> </StackLayout> <!--Botones de la pantalla:Historico/Cancelar/Aceptar--> <StackLayout Orientation="Horizontal"> <Button x:Name ="btnHistorico" Text="Historico" TextColor="Black" BackgroundColor="Yellow" HorizontalOptions="CenterAndExpand" WidthRequest="100" BorderRadius="10"/> <Button x:Name ="btnCancelar" Text="Cancelar" TextColor="Black" BackgroundColor="#e3dee2" HorizontalOptions="CenterAndExpand" WidthRequest="100" BorderRadius="10"/> <Button x:Name ="btnAceptar" Text="Aceptar" TextColor="Black" BackgroundColor="#33ff4b" HorizontalOptions="CenterAndExpand" WidthRequest="100" BorderRadius="10"/> </StackLayout> </StackLayout> </ScrollView> </StackLayout> </ContentPage>

My query is, I can add scroll view to the whole page and that this works within my listview, for the moment I do 2 scroll view for the header and footer.
Currently appears as follows:


How to add Icon in front of Entry

Detecting an element is currently within visual rendering space

$
0
0

With Xamarin Forms, is there a method for detecting if an element is currently within the visible portions of a screen?
What I am trying to achieve is the ability to detect when a user for example has scrolled on a page and if a video exists I can either stop playing it or unload it for performance reasons.

How to customize a ViewCell Xamarin.Forms

$
0
0

Hi guys, I'm trying to customize a ViewCell and I did it already in Android.

I'm following this example https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/custom-renderer/viewcell/ and this: image because in iOS, I want to use a storyboard.

So, I have the following code for the moment:

[assembly: ExportRenderer(typeof(CustomTableViewCell), typeof(NativeiOSCellRenderer))]
namespace Namespace
{
public class NativeiOSCellRenderer : ViewCellRenderer
{
ControllerCell cell;

    public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv)
    {
        var nativeCell = (CustomTableViewCell)item;
        Console.WriteLine("\t\t" + nativeCell.SpeakerName);

        cell = reusableCell as ControllerCell;
        if (cell == null)
        {
            cell = new ControllerCell(item.GetType().FullName, nativeCell);
        }
        //else
        //{
        //    cell.NativeCell.PropertyChanged -= OnNativeCellPropertyChanged;
        //}

        //nativeCell.PropertyChanged += OnNativeCellPropertyChanged;

        cell.UpdateCell(nativeCell);
        return cell;
    }

}

The PropertyChanged is not implemented yet, and in ControllerCell I have the following code:

public partial class ControllerCell : UITableViewCell
{
public CustomTableViewCell NativeCell { get; private set; }
public Element Element => NativeCell;

public ControllerCell (IntPtr handle) : base (handle)
{
}

    public ControllerCell(string cellId, CustomTableViewCell cell) : base(UITableViewCellStyle.Default, cellId)
    {
        NativeCell = cell;    
    }

    public void UpdateCell(CustomTableViewCell cell)
    {
        if (cell.SpeakerName != "")
        {
            SpeakerNameLabel.Text = cell.SpeakerName;
        }
        TitleConferenceLabel.Text = cell.TitleName;
        ConferenceHourLabel.Text = cell.ConferenceHour;
    }

}

And in CustomTableViewCell I have the same things like in the example from Xamarin site.

The problem is that SpeakerNameLabel.Text, TitleConferenceLabel.Text and ConferenceHourLabel.Text are null.

What I am missing? What can I do more? I can't find my answer anywhere, so maybe I can find some help here. Thanks!

PS. Sorry for my bad code formatting. :)

How to implement pull to refresh in listview in xamarin forms?

Xamarin.Forms don't create any files after creating solution

$
0
0

Hello, I reinstalled Visual Studio 2 times already and it didn't fix anything so I'm here. The Cross-Platform App template doesnt create any files with any selected options. Xamarin for Android works well but this doesn't. I appreciate any help.

Is there a Xamarin Forms way of handling offline?

$
0
0

Hi,

I was wondering how to handle when my device goes offline.
Is there some sort of "Xamarin forms way" of doing that? Or do I have to reinvent the wheel again?

What I would be after is to detect if the device goes offline, and notify that to the user in a nice way.

Best regards,
Tobias

How can we add SVG images asserts to Xamarin.froms app

$
0
0

we are trying to SVG images in Xamarinfroms app, so that we can reduce the app size, what are the different ways to use SVG images in Xamarin forms app ?


Anyone trying to set up SmartHotel360 reference app on their PC?

Perhaps it doesn't exist

$
0
0

Hi All,

I am getting error like below

PublicKeyToken='. Perhaps it doesn't exist in the Mono for Android profile?

This error come while making APK build (Archive for Publishing)

Add support for WPF (Windows Desktop) in a Xamarin.Forms solution

$
0
0

Tutorial Overview

In my latest tutorial we will create a cross-platform solution with Xamarin.Forms that includes WPF (Windows Desktop) as a target.
https://sites.google.com/site/netdeveloperblog/xamarin/forms/xamarin-forms-and-wpf

Cross-platform application development should reach the largest potential customer base it can. With Xamarin.Forms, you can create a solution with projects that target Android, iOS, Windows 10, Windows Mobile, Windows 8.1, and Windows Phone 8.1 out-of-the-box. Unfortunately, Windows Desktop is not included with this template. With so many people still using and relying on traditional Windows Desktop applications, many times it is important to provide a solution for that target environment.

Fortunately, with only a few modifications, we can refactor our default Xamarin.Forms solution to include a WPF project. Furthermore, we will establish a project structure that ensures all the projects can still utilized common code (things like View Models, Services, Models) from a PCL project within the solution.

We will cover the following activities:

  • Creating a new solution from the default Xamarin.Forms project template
  • Adding a Core PCL to our solution, to contain our common code
  • Add some common code to our Core PCL
  • Using a simple IoC container to replace Xamarin.Forms DependencyService class
  • Add a WPF project to our solution to target Windows Desktop
  • Implementing IHelloService in each platform
  • Creating some simple data binding in our MainPage and MainWindow views

Source Code

On GitHub: https://github.com/C0D3Name/XamFormsWpf
The source code for this tutorial can be found on my GitHub page.

How to set On().SetToolbarPlacement in MVVM ?

$
0
0

I have an XF app where the toolbar placement on UWP is set to the top, like that, in the constructor of App.xaml.cs:

        public App()
        {
            MainPage = new NavigationPage(new MainPage())
            {
                BarTextColor = Color.Black,
                BarBackgroundColor = Color.FromHex("#FFC600"),
            };
            MainPage.On<Windows>().SetToolbarPlacement(ToolbarPlacement.Top);
        }

This works as expected. Now I would like to apply the same effect in MVVM project (I am using Prism/DryIoc). But I cannot find the correct place for the On<Windows) statement above. Could someone please explain me how to implement it?

using Xamarin.Forms.PlatformConfiguration.WindowsSpecific;
using Xamarin.Forms.PlatformConfiguration;    
...
public partial class App : PrismApplication
    {
        public App(IPlatformInitializer initializer = null) : base(initializer) {  }

        protected override void OnInitialized()
        {
            InitializeComponent();
            NavigationService.NavigateAsync("NavigationPage/MainPage")
            >>>> This doesn't work:    MainPage.On<Windows>().SetToolbarPlacement(ToolbarPlacement.Top);
        }

        protected override void RegisterTypes()
        {
            Container.RegisterTypeForNavigation<NavigationPage>();
            Container.RegisterTypeForNavigation<MainPage>();
        .....

Thank you for assistance!
Marc

Accelerometer iOS and Android

$
0
0

Hi,

I'm developing an app that use accelerometer data but I'm facing lots of difference between Android and iOS.
How can I convert iOS accelerometer data to the Android one? I'm not speaking about the unit which is meter per second square con Android and g-force on iOS but I'm referring to values for the axis.

iOS has also different sign for x,y,z depending on the screen orientation....how can I normalize both in order to get just the same information?

Regards

Viewing all 58056 articles
Browse latest View live