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

How does xamarin quote css style?

$
0
0

there has no such tag

<StyleSheet></StyleSheet>

im using xamarin.forms 3.2


Displaying the image in another activity

$
0
0

Hi all, I have been trying to make an application that invokes camera through page rendering. I have used Custom Renderer from Xamarin. My problem is I need to send the picture to the other page/activity in the "Native" after clicking, but currently it is saving the picture in the gallery of the device.

For example: I click the image and then the image gets displayed with the message "Do you want to save it?". This has to be done in native rather than PCL. I have been trying through intent but that doesn't work.

Task "GenerateAppxPackageRecipe" Failed unexpectedly

$
0
0

When I try to build my project the UWP project fails. I tried it on a coworkers's computer and builds fine. But not on mine.
I've seen people saying they solved by cleaning, deleting bin/obj and rebuilding and some say they ran updates. I've tried all those to no avail.
Some say they change which msbuild.exe the project was using but none say how they did this.. if thats the solution i'd like to know how I am supposed to do it. But somehow I doubt this is going to do the trick.

Heres the error I get :

The "GenerateAppxPackageRecipe" task failed unexpectedly.
System.ComponentModel.Win32Exception (0x80004005): The specified module
could not be found
at Microsoft.VisualStudio.AppxPackage.Shared.MrmSupportLibrary.Load(String
mrmSupportLibraryPath)
at
Microsoft.Build.AppxPackage.MrmSupportLibraryResourceIndexMap..ctor(String
mrmSupportLibraryPath, String projectDir, String makePriExtensionPath)
at Microsoft.Build.AppxPackage.ResourceIndexMap.Create(String
mrmSupportLibraryPath, Boolean useResourceIndexerApi, String projectDir,
String makePriExtensionPath, ITaskItem[] indexedPayloadFiles)
at
Microsoft.Build.AppxPackage.GenerateAppxPackageRecipe.ExecuteImplementation()
at Microsoft.Build.AppxPackage.AppxPackagingTaskHelper.Execute(String file)
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.Build.AppxPackage.AppxPackagingTaskHelper.Execute(String file)
at Microsoft.Build.AppxPackage.GenerateAppxPackageRecipe.Execute()
at
Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft
.Build.BackEnd.ITaskExecution
Host.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.
d__26.MoveNext() TabletSignaturePad.UWP

Please help....

Create splash screen with multiple images

$
0
0

I want to create a splash screen with multiple images,and show it one after another,
how can i do it? thank

Can i code for a Xamarin.forms css style sheet base on platform? Can i target a style sheet?

$
0
0
  1. Is it possible to target an entire stylesheet base on platform for CSS?
  2. Is it possible to targe a specific style for a specific platform based on CSS?

Why File is not opening? FileProvider with Dependency Injection

$
0
0

Hi so i made a Dependency Injection To use the file provider in the shared project, but when i open is just like is empty because it show's that he opens the file but never show's the content:

FileDevice.cs

namespace AppQ4evo.Services
{
    public interface FileDevice
    {
        Android.Net.Uri GetFileProviderWorking(File file);
    }
}

FileAndroid.cs

[assembly: Xamarin.Forms.Dependency(typeof (FileAndroid))]
namespace AppQ4evo.Droid
{
    public class FileAndroid : FileDevice
    {


       public Android.Net.Uri GetFileProviderWorking(File file)
       {
            Android.Net.Uri uri = FileProvider.GetUriForFile(Android.App.Application.Context, "com.companyname.AppQ4evo.fileprovider", file);
            return uri;
        }
    }
}  

Resources/xml/file_path.xml

<?xml version="1.0" encoding="utf-8" ?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
   <external-path name="external_files" path="."/>
   <files-path name="files" path="."/>
   <internal-path name="internal_files" path="."/>
</paths>`

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.AppQ4evo" android:installLocation="preferExternal">
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="27" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CONTROL_LOCATION_UPDATES" />
<uses-permission android:name="android.permission.LOCATION_HARDWARE" />
<uses-permission android:name="android.permission.INSTALL_LOCATION_PROVIDER" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application android:label="AppQ4evo.Android" android:icon="@drawable/baseline_account_circle_black_18dp">
    <provider android:name="android.support.v4.content.FileProvider" android:authorities="com.companyname.AppQ4evo.fileprovider" android:grantUriPermissions="true" android:exported="false">
        <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" />
    </provider>
</application>
</manifest>`

Anexo.xaml.cs

    private async Task ListAnexos_ItemTapped(object sender, ItemTappedEventArgs e)
    {

        try
        {
            var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Storage);
            if (status != PermissionStatus.Granted)
            {
                if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Permission.Storage))
                {
                    await DisplayAlert("Need location", "Gunna need that location", "OK");
                }

                var results = await CrossPermissions.Current.RequestPermissionsAsync(Permission.Storage);
                //Best practice to always check that the key exists
                if (results.ContainsKey(Permission.Storage))
                    status = results[Permission.Storage];
            }

            if (status == PermissionStatus.Granted)
            {

                var nomeFicheiroSelecionado = ListAnexos.SelectedItem.ToString();
                var nomeEscolhido = nomeFicheiroSelecionado.Split('.')[0];
                var anexo = Task.Run(() => log.EscolheAnexo(aux, nomeEscolhido)).Result;
                var bytes = Convert.FromBase64String(anexo);

                var directory = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads);
                var file = Path.Combine(directory.ToString(), nomeFicheiroSelecionado);

                //   File.WriteAllBytes(file, bytes);

              //  Debug.WriteLine("");


                using (FileStream fs = new FileStream(file, FileMode.Append, FileAccess.Write))
                {
                    fs.Write(bytes, 0, bytes.Length);
                }

                //   Device.OpenUri(new Uri(file));


                var externalPath = global::Android.OS.Environment.ExternalStorageDirectory.Path + "/" + global::Android.OS.Environment.DirectoryDownloads + "/" + nomeFicheiroSelecionado;

               Java.IO.File filet = new Java.IO.File(externalPath);
                filet.SetReadable(true);

                string application = "";
                string extension = Path.GetExtension(file);


                switch (extension.ToLower())
                {
                    case ".txt":
                        application = "text/plain";
                        break;
                    case ".doc":
                    case ".docx":
                        application = "application/msword";
                        break;
                    case ".pdf":
                        application = "application/pdf";
                        break;
                    case ".xls":
                    case ".xlsx":
                        application = "application/vnd.ms-excel";
                        break;
                    case ".jpg":
                    case ".jpeg":
                    case ".png":
                        application = "image/jpeg";
                        break;
                    default:
                        application = "*/*";
                        break;
                }

                //   Android.Net.Uri uri = Android.Net.Uri.FromFile(filet);

                 Android.Net.Uri uri = DependencyService.Get<FileDevice>().GetFileProviderWorking(filet);

                Intent intent = new Intent(Intent.ActionView);
                intent.SetDataAndType(uri, application);
                intent.SetFlags(ActivityFlags.ClearWhenTaskReset | ActivityFlags.NewTask);

                Android.App.Application.Context.StartActivity(intent);


            }
            else if (status != PermissionStatus.Unknown)
            {
                PopupNavigation.PushAsync(new ErrorPopUp("Acesso negado. Tente novamente"));
            }
        }
        catch (Exception ex)
        {

            PopupNavigation.PushAsync(new ErrorPopUp("Erro: " + ex));
        }
    }

Anyone got a clue of what's happen here?

Can someone suggest me plugin for file picker that work for both android and IOS .

$
0
0

Can someone suggest me plugin for file picker that work for both android and IOS ?Thanks in advance

except admob, is there any other ads libraries we can use? Any good ones?

$
0
0

I only use admob before, it was working ok, but the service from them is terrible. I'm thinking of using others, but not sure if there is any other ads providers compatible with Xamarin.Forms?

Also, is there any way we can both ads providers included in the app and choose by some kind of code?

Anyone know any good ones I can try?

Thanks a lot.


Text wrapping issue on android

$
0
0

Hello,

I am working on a chat application and using frame to create a chat bubble around chats. I am facing problem as text wrapping on label is goofy. I had tried different things like layout changes but it doesn't work.

I am using xamarin forms and with the same code the issue is not with iOS. It only exist in Droid devices. I am sharing the code and screenshot of issue below.

Please note that the code I am sharing is for receiving chat.

The code is as follows:

<Grid ColumnSpacing="2" Padding="5">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="40" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Grid.Resources>

                <ResourceDictionary>
                    //Resources goes here
            </Grid.Resources>

            <Frame Grid.Row="0" OutlineColor="Transparent" Margin="5,0" Padding="8" VerticalOptions="StartAndExpand" HorizontalOptions="StartAndExpand" Grid.Column="0" BackgroundColor="#F5F4F9">
                <StackLayout>
                    <Label TextColor="#4a4a4a" Text="{Binding Text,Converter={StaticResource DecodeString}}" LineBreakMode="WordWrap">
                        <Label.FontSize>
                            <OnPlatform x:TypeArguments="x:Double" Android="15" iOS="16" />
                        </Label.FontSize>
                    </Label>
                </StackLayout>
            </Frame>

            <Label FontSize="Micro" Margin="8,0" HorizontalOptions="Start" Grid.Row="1" Grid.Column="0" Text="{Binding Time, Converter={StaticResource convertTime}}" TextColor="Gray" />
        </Grid>

In the sreenshot you can see that the extra space is occupied by label. This is not happening in iOS. Is there a way to solve the issue on droid. Any help is appreciated.

Can't catch exceptions from HttpWebRequest after Xamarin update

$
0
0

Hi,

I recently updated everything in my Visual Studio Mac installation. I still use Xamarin Forms 3.1 though.

After this update, I have got a lot of crashes from Android users (I haven't released the iOS version yet) and it seems to be related to HttpWebRequest. I use it in the following way:

        WebRequest req = HttpWebRequest.CreateDefault(new Uri(url));
        req.Timeout = TimeoutMilis;
        ...
        using (Stream dataStream = req.GetRequestStream())
        {
            dataStream.Write(data, 0, data.Length);
        }

I have a try catch around it, but it seems like these errors are not caught. The stack traces I get are not very helpful either:

        android.runtime.JavaProxyThrowable: System.AggregateException: A Tasks exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. ---> System.Net.WebException: The request was aborted: The request was canceled. 

        caused.AggregateException(s)
        System.Net.HttpWebRequest.<MyGetResponseAsync>d__243.MoveNext()<1430f9cebba746309b69090b6cda9ce8>:0
        --- End of inner exception stack trace ---
        ---> (Inner Exception #0) System.Net.WebException: The request was aborted: The request was canceled.
        System.Net.HttpWebRequest.<MyGetResponseAsync>d__243.MoveNext()<1430f9cebba746309b69090b6cda9ce8>:0

Another similar crash:

         android.runtime.JavaProxyThrowable: System.AggregateException: A Tasks exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. ---> System.ObjectDisposedException: Cannot access a disposed object. 

        caused.AggregateException(s)
        Object name: 'System.Net.Sockets.Socket'.
        System.Net.Sockets.Socket.ThrowIfDisposedAndClosed()<1430f9cebba746309b69090b6cda9ce8>:0
        System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)<1430f9cebba746309b69090b6cda9ce8>:0
        System.Net.Sockets.SocketTaskExtensions.<>c.<ConnectAsync>b__2_1(IAsyncResult asyncResult)<1430f9cebba746309b69090b6cda9ce8>:0
        System.Threading.Tasks.TaskFactory<TResult>.FromAsyncCoreLogic(IAsyncResult iar, Func<T, TResult> endFunction, Action<T> endAction, Task<TResult> promise, bool requiresSynchronization)<e7c4dd6cd0ad467d9712102a6791959b>:0
        System.Net.WebConnection.<Connect>d__16.MoveNext()<1430f9cebba746309b69090b6cda9ce8>:0
        System.Net.WebConnection.<InitConnection>d__19.MoveNext()<1430f9cebba746309b69090b6cda9ce8>:0
        System.Net.WebOperation.<Run>d__57.MoveNext()<1430f9cebba746309b69090b6cda9ce8>:0
        System.Net.WebCompletionSource<T>.<WaitForCompletion>d__15.MoveNext()<1430f9cebba746309b69090b6cda9ce8>:0
        System.Net.WebOperation.<GetRequestStream>d__49.MoveNext()<1430f9cebba746309b69090b6cda9ce8>:0
        --- End of inner exception stack trace ---
        ---> (Inner Exception #0) System.ObjectDisposedException: Cannot access a disposed object.
        Object name: 'System.Net.Sockets.Socket'.
        System.Net.Sockets.Socket.ThrowIfDisposedAndClosed()<1430f9cebba746309b69090b6cda9ce8>:0
        System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)<1430f9cebba746309b69090b6cda9ce8>:0
        System.Net.Sockets.SocketTaskExtensions.<>c.<ConnectAsync>b__2_1(IAsyncResult asyncResult)<1430f9cebba746309b69090b6cda9ce8>:0
        System.Threading.Tasks.TaskFactory<TResult>.FromAsyncCoreLogic(IAsyncResult iar, Func<T, TResult> endFunction, Action<T> endAction, Task<TResult> promise, bool requiresSynchronization)<e7c4dd6cd0ad467d9712102a6791959b>:0
        System.Net.WebConnection.<Connect>d__16.MoveNext()<1430f9cebba746309b69090b6cda9ce8>:0
        System.Net.WebConnection.<InitConnection>d__19.MoveNext()<1430f9cebba746309b69090b6cda9ce8>:0
        System.Net.WebOperation.<Run>d__57.MoveNext()<1430f9cebba746309b69090b6cda9ce8>:0
        System.Net.WebCompletionSource<T>.<WaitForCompletion>d__15.MoveNext()<1430f9cebba746309b69090b6cda9ce8>:0
        System.Net.WebOperation.<GetRequestStream>d__49.MoveNext()<1430f9cebba746309b69090b6cda9ce8>:0

Has anyone had a similar problem?

Using ResourceDictionary from another assembly compile error

$
0
0

I'm trying to use ResourceDictionary from another assembly in App.xaml like this:

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/UIServiceLib;component/ResourceDictionaries/CommonDictionary.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

and I'm getting compile error:

Invalid URI value: The specified port is invalid.

Rebuilding/cleaning solution didn't help. How can I solve this issue?

Error with Bindable property on usercontrol

$
0
0

What am I missing? Whenever I try to set the property value I'm getting the following exception thrown:

Default value did not match return type
Parameter name: defaultValue

Stack Trace...

at Xamarin.Forms.BindableProperty..ctor(String propertyName, Type returnType, Type declaringType, Object defaultValue, BindingMode defaultBindingMode, ValidateValueDelegate validateValue, BindingPropertyChangedDelegate propertyChanged, BindingPropertyChangingDelegate propertyChanging, CoerceValueDelegate coerceValue, BindablePropertyBindingChanging bindingChanging, Boolean isReadOnly, CreateDefaultValueDelegate defaultValueCreator)

My code is the following:

public class ExtendedMenu1 .....

#region ButtonWidth
public const string ButtonWidthPropertyName = "ButtonWidth";
public static readonly BindableProperty ButtonWidthProperty = BindableProperty.Create(ButtonWidthPropertyName, typeof(double), typeof(ExtendedMenu1), double.Parse("10"), BindingMode.OneWay, null, propertyChanged: OnButtonWidthChanged);

private static void OnButtonWidthChanged(BindableObject bindable, object oldvalue, object newvalue)
{
....
}

public double ButtonWidth
{
get { return (double)GetValue(ButtonWidthProperty); }
set { SetValue(ButtonWidthProperty, value); }
}

#endregion

I'm using Xamarin.Forms v2.3.2.127

How to populate pdf files in a list view

$
0
0

I want a list of PDF files in my app, with the listview how can I populate pdf files?

TaskCompletitionSource in Xamarin.Forms never completes

$
0
0

Hello,

I'm trying to implement a websocket client in my xamarin.forms application. I'm using the websocketsharp-netstandard from nuget and its working fine, the event gets triggered when the server sends something to the client.
But I want to change the event based asynchronous pattern to async/await pattern.
So a method should send the request, wait for the event to be triggered and then return the result.
Here is the code from the FormsApp I made to test, its more minimalistic and overseeable than the extract from my Xamarin.Forms app, but it's the same as in my Xamarin.Forms app:

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            socket = new WebSocket("wss://echo.websocket.org");   //This is a test websocket server which just sends back what it receives 
            socket.Connect();            
        }        
        WebSocket socket;        

        private async void button1_Click(object sender, EventArgs e)
        {        
            textBox1.Text = await GetWsMsg();
        }

        public Task<string> GetWsMsg()
        {
            TaskCompletionSource<string> tcs = new TaskCompletionSource<string>();

            socket.OnMessage += (s,e) => {

                tcs.SetResult(e.Data);                 //Here it gets stuck in Xamarin.Forms
            };
            socket.Send("Hello Websocket");
            return tcs.Task;
        }
    }    

This works well in the .NET forms app, but in Xamarin.Forms the "GetWsMsg" method never returns.
Is this a known problem in Xamarin.Forms or Is there a alternative or a workaround?
Any help highly appreciated!

Location path in Xamarin forms problems related to background updates and consistency.

$
0
0

Hi,
I'm using Xamarin.forms (v 3.2.0.871581) with Cross.GeoLocator plugin (v 4.5.0.6) in my xamarin.forms to fetch location whenever user executes a service. Like i want path user travelled from service start to service end. Path data are stored locally in sqlite db and syncing whenever service stops.
Data are saving fine but capturing data is problem since consistency is not available.

Sometimes some points are missed or location service is stopped in between(happening is some phones).
I'm trying this Geolocator with Listener settings(see below), but some path points are not captured at all(checked this DB).

ListenerSettings listenerSettings = new ListenerSettings
                                {
                                    AllowBackgroundUpdates = true, ActivityType = ActivityType.Other, DeferLocationUpdates = false,
                                    DeferralDistanceMeters = null, ListenForSignificantChanges = false, DeferralTime = null, PauseLocationUpdatesAutomatically = false
                                };
            await CrossGeolocator.Current.StartListeningAsync(TimeSpan.FromSeconds(10), 0, true, listenerSettings);

How to achieve consistency during capturing location like every 5-10 seconds?


Select Multiple image from gallery in ios.

$
0
0

I have goann with ELCImagePickerController but they said install this component which is not available. Is there any other lib that i can go for multiple selection.
Thankx in advance :smile:

Model View Bring to front

$
0
0

I have 2 views transalateTo one above the other and i made opacity 0 to the front view and i can see the behind view but i did not able to change and do action on the behind view.

Xamarin.Forms for WPF Not able to clear ListView selection

$
0
0

Hi,

Description:
Create a ListView
Assign a ObservableCollection object to Listview.ItemSource
The collection is displayed on the ListView

experiment 1:
-I change the ListView elements by reassigning a different collection to Listview.ItemSoure. This works fine.
-If I change the collection elements, it gets updated in the ListView. This also works fine.

But,

experiment 2:
-Select an item in ListView.
-After selection, when I try to change the collection (either observable or changing ItemsSource), NotImplementedException being thrown here.

I'm not able to clear the selectedItem in ListView and also not able to update the ListView after an item is selected in the ListView.

Please suggest a solution for this.

Thanks,
Chand

Button Size changed when updated to Xamarin 3.3 with FormsApplicationActivity

$
0
0

I agre that FormsApplicaitionActivity is old. But i recently updated from xamarin forms 2.5 to 3.3, and my buttons have all reduced in height . I didnt do any changed with respect to UI of the button since the upgrade.
The style CKButon and the respective shape is defined below:

        <?xml version="1.0" encoding="utf-8" ?>
        <selector xmlns:android="http://schemas.android.com/apk/res/android" >
        <item android:state_pressed="true" >
         <shape android:shape="rectangle"  android:padding="10dp">  
             <corners android:radius="3dp"/>
             <solid   android:color="#96BD0D"/>
             <stroke android:width="1dip" android:color="#96BD0D" />        
         </shape>
        </item>
        <item android:state_focused="true">
         <shape android:shape="rectangle"  android:padding="10dp">
             <corners android:radius="3dp"/>
             <stroke android:width="1dip" android:color="#96BD0D" />
             <solid android:color="#96BD0D"/>       
         </shape>
        </item>  
        <item >
        <shape android:shape="rectangle"  android:padding="10dp">
             <corners android:radius="3dp"/>
              <solid   android:color="#829293"/>
             <stroke android:width="1dip" android:color="#829293" />
         </shape>
        </item>
        </selector>

How to handle custom renderers on Android when upgrading from XF 2.x to 3.x

$
0
0

I recently upgraded from XF 2.4 to 3.2 . On Android, some of the Buttons reduced in height after re-building.

I worked out that this happened for Buttons for which I had custom renderers that inherited from Xamarin.Forms.Platform.Android.ButtonRenderer . As I use FormsAppCompatActivity, I changed those custom Button renderers to inherit instead from Xamarin.Forms.Platform.Android.AppCompat.ButtonRenderer . That resolved the height issue for Buttons.

This makes me wonder if I should go through all of my custom renderers (not just Button renderers) on Android and insert .AppCompat when inheriting from the base renderer class. Is that recommended, or is it just Buttons that are likely to hit a problem if that isn't done?

And, should the code have inherited from the .AppCompat version even on XF 2.4? (i.e. was it a bug lurking in my code that the upgrade to 3.2 highlighted, or it this a 3.x requirement that wasn't a 2.x requirement)

Viewing all 77050 articles
Browse latest View live


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