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

AppThemeColor replacement

$
0
0

Seems that in the latest version of Xamarin.Forms, the AppThemeColor is deprecated.

So the following code, with which I was able to define a color for light and dark mode is not valid anymore.

<Color x:Key="DarkBlueColor">#0A1B2F</Color>
<Color x:Key="WhiteColor">#FFFFFF</Color>

<AppThemeColor x:Key="PageBackgroundMain"
               Light="{StaticResource WhiteColor}"
               Dark="{StaticResource DarkBlueColor}"/>

With what code can I replace the depracated AppThemeColor?


cannot delete app data, where is Environment.SpecialFolder.LocalApplicationData stored?

$
0
0

Something very strange,
I use sqlite-pcl-net v1.7.302-beta
I store datas in a sqlite database.
I debug my app on a android device.

I cannot delete the datas:

  • If I delete an item, when I start the app again, the item comes back.
  • If I delete the datas of the app, the datas come back.
  • If I delete the datas and unistall the app, the datas comes back?!!

This is my App.xaml.cs code:

        public static PositionsSightsDatabase PositionsSightsDB
        {
            get
            {
                if (positionsSightsDatabase == null)
                {
                    positionsSightsDatabase = new PositionsSightsDatabase(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "PositionsSightsSQLite.db3"));
                }
#if DEBUG
                System.Diagnostics.Debug.WriteLine("db3 folder: " +  Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData));
#endif

                return positionsSightsDatabase;
            }
        }

The result is:
'/data/user/0/almicantarat.almicantarat/files/.local/share

When I browse my device, I don't find .local/share
Where are the datas stored? on my PC by VS?
Why is it impossible to delete the whole database?

How to find width of Placeholder by using length of placeholder in Entry field

$
0
0

Hi,
How to find width of Placeholder by using length of placeholder

How to use a webview with a local ip?

$
0
0

I have a local web service published by an ESP8266, from the browser of both the phone and my pc I can open it without problems, now I would like to embed that page in a webview, but when it is run it opens a blank page.

I'm trying something like this:

            browser = new WebView
            {
                Source = "https://192.168.0.77",
            };
            Content = browser;

Does anyone know if it is possible?

How to auto scale text in a label to fit the grid cell in Xamarin forms

$
0
0

In a Xamarin Forms project that target both Android and iOS I have the following grid:

`

<Grid.RowDefinitions>
    <RowDefinition Height="*" />
    <RowDefinition Height="40" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
    <ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label x:Name="row0" Grid.Row="0" Grid.Column="0" XAlign="Center" FontSize="Large" LineBreakMode="WordWrap" />
<Label x:Name="row1" Grid.Row="1" Grid.Column="0" XAlign="Center" FontSize="Large" LineBreakMode="NoWrap" />


`

The cell for row0 will grow to fit in the text as expected.
The cell for row1 is always going to be the same size and if the Text Size on the device is set to normal then the text fits fine.
However if the user adjusts the text size to be very large (for example by going to Settings -> Accessibility -> Display & Text Size -> Larger Text on an iPhone) then the text will no longer fit in the cell and it gets truncated.

I would like to be able to adjust the font size so that the text always displays on screen no matter what underlying text size the user has set on their device.

I have not been able to find a way to do this.

Any suggestions?

Thanks

Pusher with Xamarin.Forms

$
0
0

Hi there,

I'm trying to incorporate Pusher.com with my Xamarin.Forms application, but I haven't found a good solution for this yet. There is an outdated library: https://github.com/sothychan/Pusher.NET-Xamarin-Forms

But this one doesn't work when trying to install I'm getting: 'You are trying to install this package into a project that targets 'portable-net45'....

Any ideas what I can do?

POST Failed at Xamarin.UITest.Shared.Http.HttpClient.HandleHttpError

$
0
0

Hi,

I have the following error and I have no idea what it means. It does not happen in the emulator--only when it runs on a physical phone (or in appcenter with 'Test on a real device' enabled).

1) Error : AppCenter.UITest.Android.Tests.AppDoesLaunch
System.Net.WebException : POST Failed
at Xamarin.UITest.Shared.Http.HttpClient.HandleHttpError (System.String method, System.Net.Http.HttpResponseMessage response, Xamarin.UITest.Shared.Http.ExceptionPolicy exceptionPolicy) [0x00052] in <18ae7883e2424c558186d1d9edf9f14b>:0
at Xamarin.UITest.Shared.Http.HttpClient.SendData (System.String endpoint, System.String method, System.Net.Http.HttpContent content, Xamarin.UITest.Shared.Http.ExceptionPolicy exceptionPolicy, System.Nullable1[T] timeOut) [0x00123] in <18ae7883e2424c558186d1d9edf9f14b>:0 at Xamarin.UITest.Shared.Http.HttpClient.Post (System.String endpoint, System.String arguments, Xamarin.UITest.Shared.Http.ExceptionPolicy exceptionPolicy, System.Nullable1[T] timeOut) [0x00014] in <18ae7883e2424c558186d1d9edf9f14b>:0
at Xamarin.UITest.Shared.Android.HttpApplicationStarter.Execute (System.String intentJson) [0x00035] in <18ae7883e2424c558186d1d9edf9f14b>:0
at Xamarin.UITest.Shared.Android.AndroidAppLifeCycle.LaunchApp (System.String appPackageName, Xamarin.UITest.Shared.Android.ApkFile testServerApkFile, System.Int32 testServerPort) [0x000a1] in <18ae7883e2424c558186d1d9edf9f14b>:0
at Xamarin.UITest.Shared.Android.AndroidAppLifeCycle.LaunchApp (Xamarin.UITest.Shared.Android.ApkFile appApkFile, Xamarin.UITest.Shared.Android.ApkFile testServerApkFile, System.Int32 testServerPort) [0x00007] in <18ae7883e2424c558186d1d9edf9f14b>:0
at Xamarin.UITest.Android.AndroidApp..ctor (Xamarin.UITest.Configuration.IAndroidAppConfiguration appConfiguration, Xamarin.UITest.Shared.Execution.IExecutor executor) [0x00193] in <18ae7883e2424c558186d1d9edf9f14b>:0
at Xamarin.UITest.Android.AndroidApp..ctor (Xamarin.UITest.Configuration.IAndroidAppConfiguration appConfiguration) [0x00000] in <18ae7883e2424c558186d1d9edf9f14b>:0
at Xamarin.UITest.Configuration.AndroidAppConfigurator.StartApp (Xamarin.UITest.Configuration.AppDataMode appDataMode) [0x00017] in <18ae7883e2424c558186d1d9edf9f14b>:0
at AppCenter.UITest.Android.Tests.SetUp () [0x00010] in :0
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <48b95f3df5804531818f80e28ec60191>:0

Toolbar how to create custom option menu like secondary item with absolutelayout?

$
0
0

Toolbar how to create custom option menu like secondary item with absolutelayout , I could not manage background transparent that you see the content?


Same View size for All devices

$
0
0

In my Xamarin app i've a Grid with HeightRequest = 200 i've checked it on different screen size devices on android, Height is different on each device may be because of xamarin uses dp. I want it to be same on every device how can i make it to be the same size on every device.Ref Screen shot.

Started to have Problem Debugging in real android device

$
0
0

Hi guys,

I think I've already read all the similar answers and I still can't find a solution.

I started to having problem when I try it to debuggin my app in a real device, I just added a new styles (nothing big) to my app when they stop to debuggin.

I need to specify something:
1. I have previously run the application on the same device.
2. The app works and run in a emulator.
3. I have xamarin 4.8 in VS 2019 Enterprise
4. When I try to debug, the screen goes blank
5. When I remove debugging, and open the installed app, it works perfectly, but I NEED TO DEBUG some lines.

Somebody knows or have an Idea of what's the problem?

Thanks

Unable to connect to USB Device using LibUsbDotNet API

$
0
0

Hi,

I'm using LibUsbDotNet API v.2.2.29. I'm using the following statements to connect to a USB device via a smartphone from a Xamarin.Forms app:

int productId = this.MyUsbFinder.Pid;
int vendorId = this.MyUsbFinder.Vid;                

UsbDeviceFinder MyUsbFinder = new UsbDeviceFinder(productId, vendorId);
MyUsbDevice = UsbDevice.OpenUsbDevice(MyUsbFinder);

It works fine until I reach the last line (OpenUsbDevice) and it throws an exception. I tried to look at the stacktrace and this is what seems to be the problem (I'm not sure):

"Unable to cast object of type 'Mono.Debugger.Soft.PointerValue' to type 'Mono.Debugger.Soft.PrimitiveValue'."

I tried using the latest alpha version of LibUsbDotNet, but I can't get it to open my USB device either.

BTW, the USB device I'm connecting to a smartphone (Android/iOS) is a CO2 sensor measuring soil respiration, with a USB cable that I can plug into my Android. I've written a desktop version of this app and it works perfectly using Windows Forms. This version is for smartphones...if I can get over the connection issues.

Appreciate any help/tips.

Xamarin Forms Document Scanner

$
0
0

Hi,

I am searhing a document scanner for Xamarin Forms.
I tried a few solution for this. For example:
-Scanbot (it works very well but it is too expensive),
-Pixelnetica(i think this is not for Xamarin.Forms. It is for Xamarin.iOS and Xamarin.Android),
-Anyline (it is good but it doesn't take photo and crop. It only focuses text, and sometimes it takes photo after the focus. But i couldn't trigger it (take photo) myself. That's way it is not useful for me.)
-Imaging Library: https://github.com/enginkirmaci/Imaging-Library (it is so slow and it doesn't work good)

Apart from these I saw emgu.cv (it uses opencv) or I can add opencv myself. (I don't have any idea how do i scan document after add OpenCV or emgu.cv) But i am trying use Emgu.CV.

That's way i downloaded emgu.cv github repo (https://github.com/emgucv/emgucv). After that i took lots of error. Like these:

And I saw this article: https://kampeki-factory.blogspot.com/2017/12/emgu-with-xamarin-forms-guide-part-1.html
Maybe it can be usefull but it tells about how to implement emgu.cv paid version. But firstly i wanna try demo app.

Can someone help me how can i try emgu.cv demo? Or is there any other document scanner?

Shell Flyout Menu not showing correct selected item

$
0
0

Hi,

I have an app with just three pages, and tapping the hamburger menu icon opens the flyout.

If I tap a particular menu item, it navigates to the correct page, and if I tap on the menu icon again, that page is shown as selected.

Everything is right so far.

However if once in a page, I navigate programatically to another page using the registered Shell route mechanism, then when I tap on the hamburger, the selected menu item shows the previously navigated to page, not the one that is currently displayed (which was navigated to programatically).

Any ideas about how to resolve this?

I also notice that the ShellItem IsChecked property is readonly, so setting IsChecked=true in the Shell OnNavigated method is not possible:

        protected override void OnNavigated(ShellNavigatedEventArgs args)
        {
            var currentItem = this.CurrentItem;

            //currentItem.IsChecked = true;

            base.OnNavigated(args);
        }

Kind regards!

Disposing an Object

$
0
0

I am from the old school where we dispose the object that we created , my code is normally structured this way

Myclass obj = new Myclass();
try 
{
obj.MyMethod(); 
}
catch(Exception ex)
{
throw ex;
}
finally
{
obj =null
}

As you can see i am setting the created object to Null , i have noted that in Xamarin , this is actually greyed out , which means its not necessary to do . Does this mean Garbage Collector is more effective in Xamarin ? Or should i continue to dispose every object i create ?

Just an observation

Thanks

Xamarin Forms: How to open an App from the Another App?

$
0
0

I have 2 applications ( A and B ) developed using xamarin forms. I need to open the A app from the B app.

I have tried like below as per this thread:

In the view

var appname = @"otherappId";
var result = await DependencyService.Get<IAppHandler>().LaunchApp(appname);

Interface

public interface IAppHandler
{
    Task<bool> LaunchApp(string uri);
}

Android

[Activity(Label = "OpenAppAndroid")]
public class OpenAppAndroid : Activity, IAppHandler
{
    public Task<bool> LaunchApp(string uri)
    {
        bool result = false;

        try
        {
            var aUri = Android.Net.Uri.Parse(uri.ToString());
            var intent = new Intent(Intent.ActionView, aUri);
            Xamarin.Forms.Forms.Context.StartActivity(intent);
            result = true;
        }
        catch (ActivityNotFoundException)
        {
            result = false;
        }

        return Task.FromResult(result);
    }
}

IOS

public class OpenAppiOS : IAppHandler
{
    public Task<bool> LaunchApp(string uri)
    {
        try
        {
            var canOpen = UIApplication.SharedApplication.CanOpenUrl(new NSUrl(uri));

            if (!canOpen)
                return Task.FromResult(false);

            return Task.FromResult(UIApplication.SharedApplication.OpenUrl(new NSUrl(uri)));

        }
        catch (Exception ex)
        {
            return Task.FromResult(false);
        }
    }
  1. For android, I am getting System.NullReferenceException: 'Object reference not set to an instance of an object.' when running the project. I don't know what is app name in the code? I have tried with the package name.

  2. Also if the android app is not installed on the device, need to open the play store to download the app.

  3. I didn't test the ios part because Mac is not available. Is the above code work for ios? Also if the app is not installed on the iPhone, need to open the Appstore to download the app.

  4. Also, I like to implement the same for UWP.

Reference:
https://forums.xamarin.com/discussion/92666/detect-and-open-another-app-on-device
https://stackoverflow.com/questions/52062594/is-it-possible-to-open-another-app-in-my-app-with-xamarin-form


SkiaSharp Canvas to byte array or stream

$
0
0

Hey guys,

What I am trying to do is I have a popup with skiasharp and once the user finished the free drawing and click on save button I want to convert the canvas to byte array or stream and send to the other page and view the image on image control.

My Issue is I don't know how to convert the canvas to byte array. I am using below code

            SKBitmap bitmap = new SKBitmap((int)canvasView.Width, (int)canvasView.Height);
                SKCanvas canvas = new SKCanvas(bitmap);

                // create an image COPY
                //SKImage image = SKImage.FromBitmap(bitmap);
                // OR
                // create an image WRAPPER
                SKImage image = SKImage.FromPixels(bitmap.PeekPixels());

                // encode the image (defaults to PNG)
                SKData encoded = image.Encode();

                // get a stream over the encoded data
                Stream stream = encoded.AsStream();

        //publish new event                
        _aggregator.GetEvent<IncidentRepImageEvent>().Publish(stream);

        //Close the popup               
         NavigationExtension.PopPopupAsync(null, true);

and using this code to view the image on the other page

        ImageSource PhotoStream = (StreamImageSource)ImageSource.FromStream(() => obj);

                Image = PhotoStream;

iOS "Files" app, Android ExternalStorageDirectory and saving files

$
0
0

Hello,

Trying to rephrase a question I've asked before.

I'd like to save a generated .pdf file into a common folder on a device so that a user can find those files from say email app for an attachment or just view the file external to my app.

On my iOS device, I can open Files app and browser to various folders. I noticed some apps have their own folders under "On my phone" and I can manually create a folder there too.

I'd like my app to create it's own public folder on the device and save pdf files into that. The user can then view those files by simply navigating to that folder using the Files app without needing to use my app.

Found these two links - files in iOS
and this BlogPost for Android

Can anyone else advise?
As there a plugin or sample code that'll help?

I'm expecting to write a dependency service for this on each platform.

Thanks

Why Glyph property in FontImageSource doesn't bind?

$
0
0

Hi community.
I have a strange behavior with FontImageSource. I can't get property binded to Glyph.

<ContentPage.BindingContext>
        <documents:DocumentListViewModel />
    </ContentPage.BindingContext>
    <ContentPage.ToolbarItems>            
        <ToolbarItem Command="{Binding ChangeViewTypeCommand, Mode=OneWay}">
            <ToolbarItem.IconImageSource>
                <FontImageSource Glyph="{Binding ViewTypeGlyph}" Size="26" FontFamily="{x:StaticResource MaterialFontFamily}" Color="{DynamicResource PrimaryColor}"/>
            </ToolbarItem.IconImageSource>
        </ToolbarItem>
    </ContentPage.ToolbarItems>

public string ViewTypeGlyph
        {
            get
            {
                switch (this.ViewType)
                {
                    case ViewType.SmallRows:
                        return MaterialDesignIcons.ViewAgendaOutline;
                    case ViewType.BigRows:
                        return MaterialDesignIcons.CropSquare;
                    case ViewType.Grid:
                        return MaterialDesignIcons.ViewGridOutline;
                }
                return MaterialDesignIcons.ViewAgendaOutline;
            }
        }

I put a break point on the get block and it does not raise.

What am I missing?

Note: setting Glyph to static property works as well

<FontImageSource Glyph="{x:Static icons:MaterialDesignIcons.ViewAgendaOutline}" Size="26" FontFamily="{x:StaticResource MaterialFontFamily}" Color="{DynamicResource PrimaryColor}"/>

Xamarin fails to Archive the project for publication (iOS)

$
0
0

Hello everyone,
I developed a multi-platform, it builds without any error and few warning. It runs on the device in debug mode. When I set it to Release mode and trying to archive it for publication, it throws a few warning that stops the archive.

It never happened previously that warnings crash the archive processing.

these are the warnings:

*** Found conflicts between different versions of "SQLitePCLRaw.batteries_v2" that could not be resolved.

  • Found conflicts between different versions of "SQLitePCLRaw.core" that could not be resolved.
  • Found conflicts between different versions of "System.Net.Http" that could not be resolved.
  • Found conflicts between different versions of "Microsoft.CSharp" that could not be resolved.
  • Found conflicts between different versions of the same dependent assembly. Please set the "AutoGenerateBindingRedirects" property to true in the project file.
  • Obsolete member 'AppDelegate.FinishedLaunching(UIApplication, NSDictionary)' overrides non-obsolete member 'UIApplicationDelegate.FinishedLaunching(UIApplication, NSDictionary)'**

How can I archive the app? Do you have any thought?

Kind regards,
Kamal

ListView inside CarouselView scroll vertical is almost impossible.

$
0
0

I have a collection of listviews inside a horizontal CarouselView. When im trying to scroll vertically through the listview in focus, if make any tiny movement horizontally, the carousels horizontal scrolling "takes over" and makes scrolling vertically almost impossible. Anyway i can "prioritize" the listviews scrolling?

Hope it makes sense :)

Viewing all 79144 articles
Browse latest View live


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