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

Android application crashing on load with error [Xamarin.Forms]

$
0
0

Hi, I am creating a new Xamarin.Forms (Portable) project, when I tried to debug the application without any changes in default code, I am getting the below error.

Java.Lang.RuntimeException: Binary XML file line #1: Error inflating class Android.support.v7.widget.Toolbar

Please check the attached screenshot.

Thank You.


Display ListView in Full Screen

$
0
0

I am having problem with ListView, I need to show this list in Full Screen. There are 55 rows in my ItemSource.

Here is my code snippet.
`
<Grid.RowDefinitions>


</Grid.RowDefinitions>

  <Grid Grid.Row="0" BackgroundColor="#5FB1E0">
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="Auto"></ColumnDefinition>
      <ColumnDefinition Width="*"></ColumnDefinition>
      <ColumnDefinition Width="Auto"></ColumnDefinition>
    </Grid.ColumnDefinitions>
    <StackLayout Grid.Column="0" Margin="10">
      <Image x:Name="ImageMenu" Source="{local:ImageResource images.menu.png}" HeightRequest="40"></Image>
    </StackLayout>
    <Label Grid.Column="1" x:Name="LabelHome" FontSize="18" TextColor="White" VerticalTextAlignment="Center"></Label>
  </Grid>

  <StackLayout Grid.Row="1" Orientation="Vertical" VerticalOptions="Fill" HorizontalOptions="StartAndExpand">
    <ListView x:Name="listEmployeeDirectory" HasUnevenRows="True" VerticalOptions="FillAndExpand" IsPullToRefreshEnabled="True" >
      <ListView.ItemTemplate>
        <DataTemplate>
          <ViewCell>
            <StackLayout Padding="5,10">
              <Grid>
                <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="Auto"></ColumnDefinition>
                  <ColumnDefinition Width="*"></ColumnDefinition>
                </Grid.ColumnDefinitions>
                <Image Grid.Column="0" HeightRequest="50">
                  <Image.Source>
                    <UriImageSource Uri="{Binding ProfileImage}" CacheValidity="5" CachingEnabled="true" />
                  </Image.Source>
                </Image>
                <Label Grid.Column="1" Text="{Binding FullName}" HorizontalOptions="StartAndExpand"
                       VerticalTextAlignment="Center" TextColor="Black" FontSize="18" FontFamily="Droid Sans Mono" />
              </Grid>
            </StackLayout>
          </ViewCell>
        </DataTemplate>
      </ListView.ItemTemplate>
    </ListView>
  </StackLayout>
</Grid>`

xamlParseException at position 7:3

$
0
0

i understand that the error is on line 7 the (:3) confuses me cause my research says that means the position in the line but

        <Controls:HorizontalList x:Name="Work" ListOrientation="Horizontal" ItemsSource="{Binding}">

if position 3 is where the error starts from the code above..... that means Cont <-- error starts and i cant understand why

the entire error states that

Position 7:3 Type Controls:HorizontalList not found in xmlns clr-namespace:HorizontalListView;assembly=HorizontalListView

which is a different solution and assembly to the project running and it does contain the correct HorizontalList.cs in it so right now im just confused

How to play RTMP server address in Xamarin.forms (Shared)

$
0
0

I want to play RTMP server address in Xamarin.Forms (Shared), as I am a beginner and don't know much about the Xamarin.Forms (Shared). So, can anybody help in this? How to play a video with RTMP server address?

Thanks in advance.

It's possible to add Tap gesture to the Entry?

$
0
0

Hi All,
As I wrote in the title, it's possible to add Tap gesture to the Entry?
This code works for Label but doesn't work for Entry:

var tapEntryRecognizer = new TapGestureRecognizer();
            tapFocusEntryRecognizer.Tapped += async (s, e) =>
            {
                Console.WriteLine("tapped");
            };
tapEntry.GestureRecognizers.Add(tapFocusEntryRecognizer);

HttpGet with authorization header

$
0
0

I need to retrieve some json data from web service, specifically FCM, but I can't find how to do that with and authorization header.

I was trying to use the following code:

            var request = (HttpWebRequest)WebRequest.Create(new Uri(url));
            request.ContentType = "application/json";
            request.Method = "GET";

but I can't put the necessary authorization header. I don't find nothing specific and clear of how to do this.

Need help

Xamarin.Forms 2.3.4.184-pre1

$
0
0

We've pushed Xamarin.Forms 2.3.4.184-pre1 to nuget. To install the pre-release, check the pre-release option in your nuget manager and install this version.

If you’ve got a bug to report, drop us a quick report here so we can troubleshoot in detail.

Important notes

  • Xamarin.Forms 2.3.4 depends on a Xamarin installation of Cycle 8. Users upgrading from Xamarin.Forms 2.3.3 (or earlier) will experience numerous compile errors if they attempt to build without first upgrading their Xamarin installation.

  • When upgrading Xamarin.Forms, take care not to simply "update all" as that will update the Xamarin.Android.Support packages to an incompatible version. More info here.

2.3.4.184-pre1

For all the details, please read the release post here. There is SO much goodness in this release, it's actually too long for the forum.

google Map Styling


Scrollview - how to scroll to bottom programatically or automatically?

$
0
0

Hello friends,

I have a scrollview with a stacklayout inside. I add labels to the stacklayout, and I can scroll manually but i want that when i add a new label the scroll goes to the bottom of the scroll, because in this moment if i don't move it, the scroll is always at the beginning.

Any piece of advice?

Thanks a lot in advance!

Change size and font in bluetooth print

$
0
0

Hello everyone!

Sorry for the insistence, since I have asked the question before but I have not gotten an answer.

I am developing a cross-platform application, this prints receipts correctly, but I must change the size of different data, such as header, titles, etc.

The printer is an Intermec PR2, it uses the programming languages: ESC/P (modes Line Print and Easy Print), CSim (CPCL) y XSim (Ex-PCL)
(Check in this page)
http://www.intermec.com/public-files/product-profiles/mx/PR2-PR3-pp-MX.pdf

I have tried the tests with the following languages, but in the print shows me the string as seen in the previous codes

CPCL
var s = "! 0 200 200 210 1" + Environment.NewLine + "TEXT 4 0 30 40 Hello World" + Environment.NewLine + "FORM" + Environment.NewLine + "PRINT" + Environment.NewLine;

ESC/P
var s = "<--wm Hello Word <--w";

Can someone help me correct what's done to make it work, or provide an easy example of how to do it?

My printing method is the following and it works correctly but does not change the sizes I just print with the printer settings.

Code in PCL

string SelectedBthDevice = pckDispositivo.Items[pckDispositivo.SelectedIndex].ToString();

            //var s = "! 0 200 200 210 1" + Environment.NewLine + "TEXT 4 0 30 40 Hello World" + Environment.NewLine + "FORM" + Environment.NewLine + "PRINT" + Environment.NewLine;

            //var s = "<--wm Hello Word <--w";

            var s = "Hello Word";

            var a = DependencyService.Get<IBluetooth>().Imprimir(SelectedBthDevice, s);

            DisplayAlert("Aviso", a, "OK");

Code in Proyect.Droid

public string Imprimir(string pStrNomBluetooth, string pStrTextoImprimir)
        {
            try
            {
                BluetoothSocket socket = null;
                BufferedReader inReader = null;
                BufferedWriter outReader = null;

                string bt_printer = (from d in adapter.BondedDevices
                                     where d.Name == pStrNomBluetooth
                                     select d.Address).FirstOrDefault().ToString();

                BluetoothDevice device = adapter.GetRemoteDevice(bt_printer);
                UUID applicationUUID = UUID.FromString("00001101-0000-1000-8000-00805F9B34FB");

                socket = device.CreateRfcommSocketToServiceRecord(applicationUUID);
                socket.Connect();


                inReader = new BufferedReader(new InputStreamReader(socket.InputStream));
                outReader = new BufferedWriter(new OutputStreamWriter(socket.OutputStream));



                outReader.Write(pStrTextoImprimir + "\n");

                outReader.Flush();
                Thread.Sleep(1000);
                var s = inReader.Ready();
                inReader.Skip(0);
                //close all
                inReader.Close();
                outReader.Close();
                socket.Close();

                return "True";
            }
            catch (Java.Lang.Exception ex)
            {
                return ex.Message;
            }
        }

Back button xamarin forms

$
0
0

Hello everyone!

I am developing a cross-platform application, in which I must capture the event by pressing the back button.

I use this code:

protected override bool OnBackButtonPressed()
        {
            base.OnBackButtonPressed();

            Device.BeginInvokeOnMainThread(async () => {

                var result = await this.DisplayAlert("Aviso", "Desea cerrar la aplicacion?", "Si", "No");

                if (result)//Aca cierra la sesion
                {
                    var closer = DependencyService.Get<ISalir>();
                    if (closer != null)
                        closer.closeApplication();
                }
            });

            return true; //Do not navigate backwards by pressing the button
        }

I need to capture the event on the button on my device as in my screen navigation.

Anyone know how to do it?

Pull to refresh instantly removes the IsRefreshing spinner. Has something changed? Is it iOS10?

$
0
0

The issue

I've implemented a ListView with a pull-to-refresh command following this approach by James Montemagno. Recently (I believe after updating to iOS10), the pull to refresh animation broke. Here's what happens:

  1. Pulling down: The spinner fills to 360 degrees. (Expected, correct behavior)
  2. Releasing: The spinner flashes and disappears. (Expected bahavior: spinner remains at top of listview and spins until IsBusy is set to false)
  3. Completing: The list item is added to the list. (Expected, correct behavior)

I've included an animated gif that shows exactly what happens.

Sometimes, I'm seeing this error popup in the application output:

Attempting to change the refresh control while it is not idle is strongly discouraged and probably won't work properly.

Any ideas on what could be the cause of this issue?


Version info

Xamarin.Forms version 2.3.2.127
iOS 10.0


Some more info on the code behind the gif:

I've followed the code in the post I've linked above quite strictly. To simulate a web request, I'm awaiting a Task.Delay. I'm expecting the spinner to remain visible for 1000ms.

private async void ExecuteLoadNewStringCommand()
{
    if (IsRefreshing)
        return;

    IsRefreshing = true;
    LoadNewStringCommand.ChangeCanExecute();

    await Task.Delay(1000);
    ListItems.Add($"Another person ({ListItems.Count + 1})");

    IsRefreshing = false;
    LoadNewStringCommand.ChangeCanExecute();
}

My ListView is bound to an ObservableCollection<string> via xaml:

<ListView
        ItemsSource="{Binding ListItems}"
        HasUnevenRows="True"
        IsPullToRefreshEnabled="True"
        RefreshCommand="{Binding LoadNewStringCommand}"
        IsRefreshing="{Binding IsBusy, Mode=OneWay}"/>

I can provide the Xamarin studio solution or any of the .cs/.xaml files if there's more you need to see.

Listview - Select an item(row) when tap a component inside the row.

$
0
0

I wish to know how to select an row inside a Listview when tap a component inside it.

Like the code below, I have an Image, a Label and an Entry. Each one of them has a .
The Image and the Label trigger the TapGesture but the Entry don't. That's one question.
The other question is, how to select/highlight the row when I tap just the Image or the Label?

I'm digging inside the TapGesture event to find a ViewCell, but I found nothing so far.

<ListView x:Name="countsheetItemsByLocation" IsGroupingEnabled="True" GroupDisplayBinding="{Binding InventoryGroupName}"
                          ItemTapped="countsheetListView_ItemTapped" CachingStrategy="RecycleElement" >
                    <ListView.GroupHeaderTemplate>
                        <DataTemplate>
                            <ViewCell>
                                <ViewCell.View>
                                    <Grid BackgroundColor="#EAEAEA" >
                                        <Label Text="{Binding InventoryGroupName}" Style="{StaticResource labelGroupTitleStyle}" Margin="10,0,0,0" />
                                    </Grid>
                                </ViewCell.View>
                            </ViewCell>
                        </DataTemplate>
                    </ListView.GroupHeaderTemplate>
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ViewCell>
                                <StackLayout HeightRequest="80" BackgroundColor="{Binding SelectedItemBackgroundColor}">
                                    <StackLayout.GestureRecognizers>
                                        <TapGestureRecognizer x:Name="stkLocationTapGesture" NumberOfTapsRequired="1" Tapped="stkLocationTapGesture_Tapped" />
                                    </StackLayout.GestureRecognizers>
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="60*" />
                                            <ColumnDefinition Width="15*" />
                                            <ColumnDefinition Width="15*" />
                                            <ColumnDefinition Width="10*" />
                                        </Grid.ColumnDefinitions>
                                        <Grid.RowDefinitions>
                                            <RowDefinition/>
                                            <RowDefinition/>
                                        </Grid.RowDefinitions>
                                        <Label Grid.Column="0" Grid.Row="0" Text="{Binding ItemName}" Style="{StaticResource labelStyle}" VerticalOptions="Start" Margin="10,0,0,0">
                                            <Label.GestureRecognizers>
                                                <TapGestureRecognizer x:Name="labelTapGesture" NumberOfTapsRequired="1" Tapped="labelTapGesture_Tapped"/>
                                            </Label.GestureRecognizers>
                                        </Label>
                                        <CustomRenderers:MyEntry Grid.Column="1" Grid.RowSpan="2" x:Name="txtCountByLocation" Text="{Binding CaseCount}"  TextColor="Black" FontSize="14"
                                                                     HorizontalTextAlignment="End" Keyboard="Numeric" IsEnabled="{Binding Selected}" NeedToFocus="{Binding Selected}" Focused="txtCountByLocation_Focused" Unfocused="txtCountByLocation_Unfocused">
                                            <CustomRenderers:MyEntry.GestureRecognizers>
                                                <TapGestureRecognizer x:Name="txtCountByLocationTapGesture" NumberOfTapsRequired="1" Tapped="txtCountByLocationTapGesture_Tapped" Grid.RowSpan="2"/>
                                            </CustomRenderers:MyEntry.GestureRecognizers>
                                        </CustomRenderers:MyEntry>
                                        <Image Grid.Column="3" Grid.RowSpan="2" Source="ic_info.png" HorizontalOptions="End" x:Name="imgSelectCountsheet" IsVisible="true" Margin="0,0,10,0">
                                            <Image.GestureRecognizers>
                                                <TapGestureRecognizer  NumberOfTapsRequired="1" Tapped="TapGestureRecognizer_Tapped_1"/>
                                            </Image.GestureRecognizers>
                                        </Image>
                                    </Grid>
                                </StackLayout>
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>

AppSettings Reader for Xamarin and Xamarin.Forms

$
0
0

Reading app.config files in a Xamarin.Forms Xaml project

While each mobile platforms do offer their own settings management api, there are no built in ways to read settings from a good old .net style app.config xml file; This is due to a bunch of good reasons reasons, notably the .net framework configuration management api being on the heavyweight side, and each platform having their own file system api.

So we built a simple PCLAppConfig library nicely nuget packaged for your immediate consumption.

This library makes use of the lovely PCLStorage library

This example assumes you are developing a Xamarin.Forms Xaml project, where you would need to access settings from your shared viewmodel.

FOR FILESYSTEM APP.CONFIG

Initialize ConfigurationManager.AppSettings on each of your platform project, just after the ‘Xamarin.Forms.Forms.Init’ statement, as per below:
iOS (AppDelegate.cs)

Xamarin.Forms.Forms.Init();
ConfigurationManager.Initialise(PCLAppConfig.FileSystemStream.PortableStream.Current);
LoadApplication(new App());

Android (MainActivity.cs)

Xamarin.Forms.Forms.Init(this, bundle);
ConfigurationManager.Initialise(PCLAppConfig.FileSystemStream.PortableStream.Current);
LoadApplication(new App());

UWP / Windows 8.1 / WP 8.1 (App.xaml.cs)

Xamarin.Forms.Forms.Init(e);
ConfigurationManager.Initialise(PCLAppConfig.FileSystemStream.PortableStream.Current);
LoadApplication(new App());

Add an app.config file to your shared PCL project, and add your appSettings entries, as you would do with any app.config file

<configuration>
  <appSettings>
    <add key="config.text" value="hello from app.settings!" />
  </appSettings>
</configuration>

Add this PCL app.config file as a linked file on all your platform projects. For android, make sure to set the build action to ‘AndroidAsset’, for UWP set the build action to ‘Content’
Access your setting:

ConfigurationManager.AppSettings["config.text"];

FOR EMBEDDED APP.CONFIG

Initialize ConfigurationManager.AppSettings on your pcl project like below:

Assembly assembly = typeof(App).GetTypeInfo().Assembly;
ConfigurationManager.AppSettings = new ConfigurationManager(assembly.GetManifestResourceStream("DemoApp.App.config")).GetAppSettings;

Add an app.config on your shared pcl project and ensure that Build Action:EmbeddedResource, and add your appSettings entries, as you would do with any app.config
The source code and demo app are available in github

Problem with slide menu - Hamburger

$
0
0

Hello I have a problem with slide menu.
I have a hamburger menu with MasterDetailPage:
http://i.imgur.com/jbi8pqR.png

but when I click it, navigation bar is behind menu, I wanna move icon right to see it:

http://i.imgur.com/VN7tQ1G.png

or if it is possible to do it like in this app (You can see a little of site):
http://i.imgur.com/orrBhIO.png

My code:

<?xml version="1.0" encoding="utf-8" ?>
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:EventOrganizer; assembly=EventOrganizer"
             x:Class="EventOrganizer.MainMenu">
  <MasterDetailPage.Master>
        <local:MenuItemsPage></local:MenuItemsPage>
  </MasterDetailPage.Master>
  <MasterDetailPage.Detail>
  </MasterDetailPage.Detail>
</MasterDetailPage>

<?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:EventOrganizer; assembly=EventOrganizer"
             Title="MenuItems"
             Icon="hamburger.png"
             x:Class="EventOrganizer.MenuItemsPage">
               <StackLayout Orientation="Vertical">
                 <ListView x:Name="listView"></ListView>
      </StackLayout>
</ContentPage>

<?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:EventOrganizer, assembly=EventOrganizer"
             x:Class="EventOrganizer.HomePage">
  <Label Text="{Binding MainText}" VerticalOptions="Center" HorizontalOptions="Center" />
</ContentPage>

public partial class MainMenu : MasterDetailPage
    {
        public MainMenu()
        {
            InitializeComponent();
            this.Detail = new NavigationPage(new HomePage());
        }
    }
}

public class App : Application
    {
        public App()
        {
            MainPage = new MainMenu();
        }
    }

I will be grateful for help.


Best practice using Authorization onResume

$
0
0

I am new to Xamarin and getting started on building an app. I need to communicate to a REST API which uses token based Auth. I looked at XAMARIN.Auth and was using that to store the user name and the Token after login.
The Auth token expires after sometime. When the user resumes the app from the background, what is the best practice to see if they need to login or use the existing token?

Disabled button style

$
0
0

I'm using MVVM approach described here.

To control a button behaviour I use ICommand binding with CanExecute flag. Everything works.

But how can I control disabled button style (background color and text color) in XAML?

Confused about image size

$
0
0

Hi
Im a little confused about what image sizes to use if im building a iOS and Android app.
Do i calculate imagesize based on all iOS screensizes, and all the most popular Android screensizes?
Any suggestions?

Best regards
Jakob

Entry ReadOnly?

$
0
0

Does anyone know how to simulate a ReadOnly property for the Entry control since it doesn't exist? I'm hoping that there is an easier way than writing a custom render for each platform.

Thanks,
Steve

Failed to load class for googlecertificates error on Google Map

$
0
0

Basically I have this showing in my console after launching my app wich have GoogleMap api

Is there any way to add this dependency on my Android App?

Viewing all 91519 articles
Browse latest View live


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