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

ZXing Barcode scanning(code128 format) is not working in Xamarin Forms

$
0
0

We using the ZXING library to scan the barcodes for xamarin forms app and its working fine.

But now are having issue with barcode - code128 format as its not scanning the bar codes (content length - 19 char ). Attached barcode for reference.

We using Zxing version - 2.4.1(Latest stable).

We have used the below code but its not working for both Android & iOS platforms.

Kindly suggest/provide your inputs on resolving the issue.

` private void Btn_BarcodeClicked(object sender, EventArgs e)
{
try
{
var options = new ZXing.Mobile.MobileBarcodeScanningOptions();
options.PossibleFormats = new List<ZXing.BarcodeFormat>() {
ZXing.BarcodeFormat.CODE_39,
ZXing.BarcodeFormat.CODE_93,
ZXing.BarcodeFormat.CODE_128,
ZXing.BarcodeFormat.EAN_13,
ZXing.BarcodeFormat.QR_CODE
};
options.TryHarder = false;
options.BuildBarcodeReader().Options.AllowedLengths = new[] { 44 };

            var scanPage = new ZXingScannerPage(options);
            scanPage.DefaultOverlayTopText = "";
            scanPage.DefaultOverlayBottomText = "";
            scanPage.AutoFocus();
            ToolbarItem toolbarItem = new ToolbarItem();
            toolbarItem.Text = "Flash ON";
            toolbarItem.Clicked += (s, ex) =>
            {
                try
                {
                    toolbarItem.Text = "Flash " + (toolbarItem.Text == "Flash ON" ? "OFF" : "ON");
                    //if (scanPage.HasTorch)
                    scanPage.ToggleTorch();
                }
                catch (Exception exx)
                {
                }
            };
            scanPage.ToolbarItems.Add(toolbarItem);
            TimeSpan ts = new TimeSpan(0, 0, 0, 1, 0);
            Device.StartTimer(ts, () =>
            {
                if (scanPage.IsScanning)
                    scanPage.AutoFocus();
                return scanPage.IsScanning;
            });
            scanPage.OnScanResult += (result) =>
            {
                scanPage.IsScanning = false;
                Device.BeginInvokeOnMainThread(async () =>
                {
                    await DisplayAlert("Alert", result.Text, "Ok");
                });
            };
            Navigation.PushAsync(scanPage);
        }
        catch (Exception ex)
        {

        }
    }`

ZXing, Very First time open the app

$
0
0

Hi to all,
I am using the ZXing.Net.Mobile library for scanning barcodes in my app.
When the user download the app from the store, the very first time, it asks for Camera permitions. If the user click yes, the app continues but the ZXingScannerView is not enable for scanning.
If the user close the app open again, all works just fine.
Any ideas what I am missing?

Thanks in advance

How to change Layout Right to Left in Xamarin.Froms ?

$
0
0

Hi All,

I am working on application which will support Arabic.
Now my question is, when i change my device language the UI of setting is changed to RightToLeft(RTL). I wanted to know how this is possible in Xamarin.Forms Application. Ui change from default to RTL when device language Arabic is selected.

Thanks in advance

Xamarin ListView text not showing C#

$
0
0

Hi i have created a list view to show a table from a local database using C# but for some reason the text is not showing but the ListView boxes are. I have even tried making sure the text was the right colour in the styles.xml

Here is my code i use to get the listview and fill it with the database entry:

   `public class GetAllCompaniesPage : ContentPage
    {
        private ListView _listView;
        string _dbPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "myAppDB.db");

        public GetAllCompaniesPage()
        {
            this.Title = "Companies List";

            var db = new SQLiteConnection(_dbPath);

            StackLayout stackLayout = new StackLayout();

            _listView = new ListView();
            _listView.ItemsSource = db.Table<Company>().OrderBy(x => x.Name).ToList();
            stackLayout.Children.Add(_listView);

            Content = stackLayout;

        }
    }`

Here is my Company Model as well.

        `public class Company
        {
            [PrimaryKey]
            public int Id { get; set; }
            public string Name { get; set; }
            public string Address { get; set; }

            public override string ToString()
            {
                return this.Name + "(" + this.Address + ")";
            }
        }`

Xamarin Forms - How to open specific page after clicking on notification when the app is closed?

$
0
0

i want to open a specific page when i recieve notifcation when my app is closed i have tried but i not able to do it. Here is my code

  protected override void OnStart ()
        {
 CrossFirebasePushNotification.Current.OnNotificationOpened += (s, p) =>
            {
                try
                {
                    if (p.Data["open_page"].ToString() == "NewInPatient")
                    {
                        MainPage = new NavigationPage(new MainPage()
                        {
                            Detail = new NavigationPage(new Patients(long.Parse(p.Data["mr_no"].ToString())))
                            {

                                BarBackgroundColor = Color.FromHex("#2F3C51"),
                            }
                        });

                    }

                    else if (p.Data["open_page"].ToString() == "NewConsultancy")
                    {
                        MainPage = new NavigationPage(new MainPage()
                        {
                            Detail = new NavigationPage(new Consultants(long.Parse(p.Data["mr_no"].ToString())))
                            {

                                BarBackgroundColor = Color.FromHex("#2F3C51"),
                            }
                        });

                    }
                    else if (p.Data["open_page"].ToString() == "NewAppointment")
                    {
                        MainPage = new NavigationPage(new MainPage()
                        {
                            Detail = new NavigationPage(new Appointments(Convert.ToDateTime(p.Data["appointmentDate"])))
                            {

                                BarBackgroundColor = Color.FromHex("#2F3C51"),
                            }
                        });

                    }

                }
           }

Button with Image and Text

$
0
0

Hi,
I have a Button with an Image inside, but my users think that a picture with text would be better. The problem is, when the resolution is not too big, text and image takes too much place. A better solution is, when the display/resolution is big enough, show the picture with text otherwise the image only. I took a look into the VisualStateManager stuff, but do not know how I to trigger the different states by changing the resolution. This XAML style I place into the button style:

               <VisualStateManager.VisualStateGroups>
                    <VisualStateGroup x:Name="ShowTextStates">
                        <VisualState x:Name="ShowText">
                            <VisualState.Setters>
                                <Setter Property="Text" Value="Test test test..." />
                            </VisualState.Setters>
                        </VisualState>
                        <VisualState x:Name="HideText">
                            <VisualState.Setters>
                                <Setter Property="Text" Value="" />
                            </VisualState.Setters>
                        </VisualState>
                    </VisualStateGroup>
                </VisualStateManager.VisualStateGroups>

How can I solve this problem? Any suggestions? Thank you!

set custom font in webview

$
0
0

I want to set my own custom font in webview.

WebView Description = new WebView(this.Context); WebSettings settings = Description.Settings; settings.FixedFontFamily = "DIN-Condensed-Bold.ttf";

I have added my Font called DIN-Condensed-Bold.ttf in Assets/fonts folder, but I don`t see the effect.
Is it build action problem? How can I implement it?

Global Exception Handling

$
0
0

Hi Everyone. I'm in my final submission of my Xamarin forms App. I want to handle Exceptions Globally in my Project. I tried this https://peterno.wordpress.com/2015/04/15/unhandled-exception-handling-in-ios-and-android-with-xamarin/ but it's not working.

    AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
        TaskScheduler.UnobservedTaskException += TaskSchedulerOnUnobservedTaskException;  

The above methods are not invoking when any exception raised. Any kind of help will be appreciated.


How can we use .aar files in xamarin.forms Android project?

$
0
0

I want to use .aar files in xamarin.forms android project. I tried with Binding Library, but unable to access classes from .aar file. Can any one suggest me how to do that?
Thanks in Advance.

How to show a text from html content in Xamarin.Forms.Platform.WPF?

$
0
0

I am working to show a label. We are receiving the HTML content, we have to get a text from HTML content and need to show as a label. I am unable to get the text from HTML content. If anyone has a solution please let me know. Thanks in advance.

How to bind and pass from parameters on button command

$
0
0

I have a simple form screen, on click on button I need to pass those from elements to api call. I am not able to pass command parameter as model value . Here is my code.

Xaml page

    <ContentPage.Content>
        <ScrollView>
         <StackLayout Spacing="20" Padding="20" >
               <Label TextColor="#77d065" FontSize = "20" Text="Your Personal Details" />

                <Entry x:Name="FirstName" Placeholder="First Name"
                       Text="{Binding firstname}"/>
                <Entry x:Name="LastName" Placeholder="Last Name"
                       Text="{Binding lastname}"/>
                <Entry x:Name="Email" Placeholder="E-Mail"
                       Text="{Binding email}"/>
                <Entry x:Name="Telephone" Placeholder="Telephone"
                       Text="{Binding telephone}"/>

                <Label TextColor="#77d065" FontSize = "20" Text="Your Address" />


                 <Entry x:Name="Address" Placeholder="Address"
                       Text="{Binding address_1}"/>
                <Entry x:Name="City" Placeholder="City"
                       Text="{Binding city}"/>
                <Entry x:Name="PostCode" Placeholder="PostCode"
                       Text="{Binding postcode}"/>
                <Entry x:Name="Country" Placeholder="Country"
                       Text="{Binding country_id}"/>

                <Entry x:Name="State" Placeholder="State"
                       Text="{Binding State}" />

            <Button x:Name="nextBtn" Text="Next" TextColor="White"
                BackgroundColor="#77D065"
                Command="{Binding NextBtnCommand}" VerticalOptions="End"/>

            </StackLayout>
        </ScrollView>

    </ContentPage.Content>

Xaml Code behind

                    BindingContext = new GuestCheckOutViewModel();

                    GuestUser user = new GuestUser()
                    {
                        firstname = FirstName.Text,
                        lastname = LastName.Text,
                        email = Email.Text,
                        telephone = Telephone.Text,
                        address_1 = Address.Text,
                        city = City.Text,
                        postcode = PostCode.Text,
                        country_id = "99",
                        zone_id = "4231"
                    };


                    nextBtn.CommandParameter = user;

And view model

     public class GuestCheckOutViewModel : INotifyPropertyChanged
        {

            public GuestUser GuestUserResult { get; private set; }
            public ICommand NextBtnCommand { get; private set; }

            public GuestCheckOutViewModel()
            {
                NextBtnCommand = new Command<GuestUser> (GuestCheckOutNext);
            }

            void GuestCheckOutNext(GuestUser guestUser){



                Debug.WriteLine("name {0}", guestUser.firstname);
                Debug.WriteLine("name {0}", guestUser.lastname);
                Debug.WriteLine("name {0}", guestUser.email);
                Debug.WriteLine("name {0}", guestUser.telephone);


                OnPropertyChanged("GuestUserResult");

            }

            public event PropertyChangedEventHandler PropertyChanged;
            void OnPropertyChanged([CallerMemberName]string propertyName = "") =>
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));

        }

How can I use command and databinding in this simple form page

How to save an audio file(for example .wav file) locally other than in the project

$
0
0

I need to save an audio file locally other than in the project and read from that local folder and play it. Is there a way to do that in xamarin?

Bluetooth classic example with Xamarin for UWP (RFCOMM)

$
0
0

Hi all;

I am looking for any examples or clues for RFCOMM server (bluetooth classic) sample for Xamarin UWP, any help for me?

How can I change a WebView user-agent?

$
0
0

Hi everybody!

I'm trying to make an hybrid app for my current webapp in Xamarin.Forms Portable App, I'm creating a ContentPage Class with a custom WebView object like this:

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

namespace MyHybridApp
{
public class Navigator : ContentPage
{
public Navigator()
{
WebView visor = new WebView()
{
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
Source = "{URL_to_my_webapp_social_login}"
};
Content = visor;
}
}
}

The problem is that, when I open the app and try to login in my webapp using Google OAuth, Google give me this error:

**403. That's an error.

Error: disallowed_useragent

Google can't sign you safely inside this app.
You can use Google sign-in by visiting this app's website in a browser like Safari or Chrome.**

Can anybody help me to avoid that? The User-Agent can be changed on a WebView? And, How can I do that?

Thanks a lot!

How to add path to Webview

$
0
0

Hi,

I want to add a manual to my application. The manual is written in HTML5. As I see I only have the possiblility to add the content by using WebView.

I already checked: https://docs.microsoft.com/de-de/xamarin/xamarin-forms/user-interface/webview?tabs=windows#Local_HTML_Content

and I am able to add a webpage with:

var browser = new WebView
{
  Source = "http://xamarin.com"
};

and a Html string with:

var browser = new WebView();
var htmlSource = new HtmlWebViewSource();
htmlSource.Html = @"<html><body>
  <h1>Xamarin.Forms</h1>
  <p>Welcome to WebView.</p>
  </body></html>";
browser.Source = htmlSource;

But what I really want, is to set a path to my HTML file. How can I set this path? I could not find any working example and the description in the documentation does not work for me.

I already tried:

var browser = new WebView();
var htmlSource = new HtmlWebViewSource();
htmlSource.BaseUrl = "file:///./Manual/";
browser.Source = htmlSource;

Can somebody please help me?


Include folder in the package only in debug mod

$
0
0

Hello,

Can I specify a folder add only in debug mod on the app ?

Thanks

Formatting a string in Label

$
0
0

Hey there. Im using crossplatform Xamarin.Forms

Is there an easy way of formatting a string looking like this:

string uText = "This **is** *just* a __small test__ yup";

Where "is" is bold, "just" is italic and "small test" is underlined?

Because the idea I have is a long way to go.

I would do an

                FormattedString formatMyString(string aString)
                {
                    FormattedString formattedString = new FormattedString();
                }

methode. I would search for an * or _ then add an new Span to formattedString from char 1 to * or _ to which I dont give any FontAttributes.
Then I would look for the next * or _ and would give the text between those characters an FontAttribute and so on.
Is there an easier way to do this?

If it matters: Im receiving an webapi string where I could get such a string.

uwp scaling issue with strokecontainer vs. image

$
0
0

I've been having the most maddening scaling issue, I'm hoping someone else has seen this one before.

I have a very basic image/inkCanvas on my page. Here is the xaml.

Open Bracket Image x:Name="image" Margin="0" Grid.Row="1"/ Close Bracket
Open Bracket InkCanvas x:Name="inkCanvas" Margin="0" Grid.Row="1"/ Close Bracket

On the back side the code that saves the images looks like this:

internal async Task<byte[]> GetImageAsBytes()
{
var device = CanvasDevice.GetSharedDevice();
using (var canvasBitmap = (!string.IsNullOrWhiteSpace(BackgroundImagePath) && File.Exists(backgroundImagePath)) ?
await CanvasBitmap.LoadAsync(device, BackgroundImagePath) : null)
{
var renderTarget = new CanvasRenderTarget(device, (int)inkCanvas.ActualWidth, (int)inkCanvas.ActualHeight, 96);
using (var session = renderTarget.CreateDrawingSession())
{
session.Clear(Colors.White);
if (canvasBitmap != null)
{
session.DrawImage(canvasBitmap);
}
session.DrawInk(inkCanvas.InkPresenter.StrokeContainer.GetStrokes());
}
var stream = new InMemoryRandomAccessStream();
await renderTarget.SaveAsync(stream, CanvasBitmapFileFormat.Png);
return await ConvertStreamToBytes(stream);
}
}

On iOS and Android, all is well. When I emulate a UWP device on my laptop using visual studio's emulator, all is well. But when I use a surface (Home or Pro, both show the issue) I get a scaling issue.

In particular, the issue is that the strokes are shrunk down and stored in the upper left of the image. So if I take a picture of an object and draw a box around it on the screen, once I've saved the image the picture ends up in the upper left corner of the image, no longer around the object.

It feels like the problem has to be with the surface having a higher resolution camera, or something similar, but I don't get why the strokes would not still be synced with the size of the canvas. Has anyone got an idea what might be going on here, and how I might solve it?

-Thanks,
Walter Langendorf

Animation working on Android not working on iOS!

$
0
0

Hi,

I have the following XAML:

    <ListView SeparatorVisibility="None" x:Name="Categoriess" IsVisible="True" ItemTapped="Categories_OnItemSelected" HasUnevenRows="False"  HorizontalOptions="StartAndExpand">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ViewCell Appearing="CategoryMainAppearing" >
                                <ViewCell.View>
                                    <StackLayout VerticalOptions="Center">
                                        <Grid RowSpacing="25">
                                            <Grid.RowDefinitions>
                                                <RowDefinition  Height="*"/>
                                            </Grid.RowDefinitions>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="5*"/>
                                                <ColumnDefinition Width="90*"/>
                                                <ColumnDefinition Width="5*"/>
                                            </Grid.ColumnDefinitions>

                                            <forms:CachedImage VerticalOptions="Center" Grid.Column="0" Source="{Binding image}" />
                                            <Label VerticalOptions="Center"  Text="{Binding name}" Grid.Column="1" />

                                            <!--<Label Text=" > " FontSize="Medium" Grid.Column="2" />-->
                                        </Grid>
                                    </StackLayout>
                                </ViewCell.View>
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>

And here is my code behind:

    Categoriess.TemplatedItems.Last().Appearing += LastAppered;


  private async void LastAppered(object sender, EventArgs e)
        {
            //await Task.Delay(500);


            foreach (var cell in Categoriess.TemplatedItems)
            {
                var item = (ViewCell)cell;

                var children = item.LogicalChildren.ToList();
                //await item.View.TranslateTo(500, 0, 7, Easing.SinIn);
                await item.View.TranslateTo(0, 0, 200, Easing.SinInOut);
            }


        }

It is working perfectly fine on Android but on iOS I can't even hit a breakpoint (LastAppeared is not even being called!)

how I can go to a screen position automatic?

$
0
0

Hi, I have a question about to go on a screen position.
I have a searchbar and from there Im push to a new Page, then I need to go to the place (its a long page with text and photos) but I don't know which controls I can use??

        private void AlimentosList_ItemTapped(object sender, ItemTappedEventArgs e)
        {
            if (e.Item as string == null)
            {
                return;
            }
            else
            {
                AlimentosList.ItemsSource = alimento.Where(c => c.Equals(e.Item as string));
                AlimentosList.IsVisible = true;
                SearchContent.Text = e.Item as string;
                if (e.Item as string == "Aguacate")
                {
        //here Im push to the other page 
                    Navigation.PushAsync(new CorazonPage());

                }
            }

        }
Viewing all 89864 articles
Browse latest View live


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