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

How to use C# Markup with a CollectionView?

$
0
0

I was checking out how to use the new C# Markup functionality in my Xamarin.Forms app and I tried to implement it in a list.
However upon checking the documentation, I couldn't find an example on how to implement it. So I tried it like this:

Page code, viewModel.Init() just gets the data for technologies:

protected override void OnAppearing()
        {
            base.OnAppearing();
            viewModel.Init();
            Content = new CollectionView
            {
                BackgroundColor = Color.Purple,
                ItemTemplate = new DataTemplate(typeof(TechCardView))
            }.Bind(ItemsView.ItemsSourceProperty, nameof(viewModel.Technologies));
        }

ViewModel code just in case:

public override void Init()
        {
            _ = GetStockTechnologies();
        }

        private async Task GetStockTechnologies()
        {
            Technologies = await _getTechnologies.BuildUseCaseTaskAsync(null);
        }

I thought this would work because Technologies is a IEnumerable of TechObject, and inside TechCardView I have only one property that is of type TechObject, but I couldn't find a way to do a {Binding .} inside DataTemplate like I would in XAML.

This is what I could get with the documentation in C# Markup and the DataTemplate documentation and while I do get data, the list does not show any items.

What's the proper way to do this?


RadioButton does not work in Xamarin Forms

$
0
0

Here is my code snippet in a Xamarin xaml form:

                <StackLayout Grid.Row="5" Orientation="Horizontal">
                    <Label Text="Gender" FontSize="Small" />
                    <RadioButton Text="Male"/>
                </StackLayout>

I have the following in my App constructor

    public App()
    {
        InitializeComponent();
        Device.SetFlags(new string[] { "RadioButton_Experimental" });

}

I get the following error:

System.TypeLoadException: 'Could not resolve type with token 0100009d from typeref (expected class 'Xamarin.Forms.RadioButton' in assembly 'Xamarin.Forms.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null')'

I am using Xamarin Forms 4.8.0.1687 and Xamarin Essentials 1.5.3.2

Any and all help will be appreciated.

Is there a way to determine if you are on the Main thread?

$
0
0

In Windows Forms, all controls had an InvokeRequired property that returned true if the current thread was not the UI thread. This allowed a boilerplate pattern for ensuring a method that could be called from multiple contexts was always called from the right one:
if (someControl.InvokeRequired) { someControl.Invoke(() => ThisMethod()); } else { // do stuff }

I know in Xamarin.Forms I can use Device.BeginInvokeOnMainThread() to marshall a call to the main thread, but is there a way to detect if I'm on the main thread? That would be helpful for creating classes that represent things with thread affinity and want to enforce it.

Set Visual as Material in a CustomEntry

$
0
0

I am using a custom Entry for hiding the underline. But how i can also set visual as material?

public class MyEntry : Entry
    {
    }

[assembly: ExportRenderer(typeof(MyEntry), typeof(MyEntryRenderer))]
namespace SelfOrder.Droid
{
    class MyEntryRenderer : EntryRenderer
    {
        public MyEntryRenderer(Context context) : base(context)
        {
        }

        protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
        {
            base.OnElementChanged(e);

          //  e.visu.Visual = "Material" as VisualElement;
            if (Control != null)
            {
                Control.SetBackgroundColor(global::Android.Graphics.Color.Transparent);
            }
        }
    }

If i will set Visual as Material inside my xml,unfortunately it doesn't work.

How can I prevent Xamarin Forms webview “webpage not available” page

$
0
0

I use XF webview and check the connection status, when the connection is broken, I want to prevent the error page and keep it on that page. Is this possible?

How to implement a complex slider in xamarin.forms

$
0
0

Hi,
I have a design that im trying to implement, and part of the design is this slider:

the user interraction should be disabled for it.
The yellow thumb should be set to a value from a remote query.
Any ideas how i can implement this view? I doesnt nessessarily have to be a slider... just something that functions like i described...

Xamarin Forms and DropBox - get " Bad HTTP Content-Type" error when downloading file

$
0
0

Hi all,

I was sure I'd posted this question to the forums already but my profile does not show any questions having been posted so I'm trying again.

Ok, so I have an existing Winsdows10 UWP app called "PassPort" which uses v2 of the standard DropBox API to upload and download data files without issue. Now I want to get this app working on my Android phone (Nokia 8 running Android 8.1) so I created a XF project, copied my download/upload code over to the main project and added Xamarin.Dropbox API from NuGet. I can create a valid Dropbox session, get basic stuff like user details etc but when I try to download a file I get this error:

Error in call to API function "files/download": Bad HTTP "Content-Type" header: "application/x-www-form-urlencoded". Expecting one of "text/plain", "text/plain; charset=utf-8", "application/octet-stream", "application/octet-stream; charset=utf-8".

Now I cannot see anywhere in the Xamarin.Dropbox API that allows me to specify a content-type for the header so I am really stuck!

Here is the code I'm using to download the file - this works perfectly every time with the standard Dropbox API.

    public static async Task<string> DownloadFile(string filePath, string fileName)
    {
        string output = null;

        try
        {
            if (dbxClient == null)
                dbxClient = new DropboxClient(accessToken);

            if (dbxClient != null)
            {
                var downloadResponse = await dbxClient.Files.DownloadAsync(filePath + fileName);
                var output = await downloadResponse.GetContentAsStringAsync();
            }
            else
                throw new Exception("DownloadFile: DropBox client not authenticated");

        }
        catch (Exception ex)
        {
            Exception = ex;
            output = ex.Message;
        }

        return output;
    }

Now I'll admit this is my first Xamarin Forms project so perhaps I'm doing something wrong but the app runs perfectly Ok on the "Android_accelerated_c86_Oreo" 8.1 emulator until I try to run the above code...so does anyone know how I can resolve this?

Please don't tell me to post over on the official Dropbox forums - I did that and they replied that as it's a Xamarin specific version of the Dropbox API, I would need to ask over here on the Xamarin forums.

publishing xamarin android app (unfortunately , has stopped) android 4.4 kitkat

$
0
0

hello guys i got this message after i release the version although if i debug that one at visual it works fine and as release from visual too it works fine
works at android 10 and 7 too fine
my minimum 19 api

as that my screen say




Screenshot location on Android emulator (Windows+ Visual Studio 19)

$
0
0

Hi folks!

I can not find the screenshot location for my Android emulator on Visual Studio (Windows).
So how do I get the screenshots?

Thanks in advance!
BR
Janos

The HeightRequest or FontSize to android height or fontsize?

$
0
0

When I set the HeightRequestI can do this:

<StackLayout HeightRequest="44"></StackLayout>

but If the android is 44dp what show I set ?

if the android font-size is 22sp.

how to set the FontSizeProperty?

how to set the font weight?

$
0
0

I want to set the font-weight to Mediumof a Label.

I search the forums that I should set Font="Medium,22" but there is no such property .

what should I do?

Getting "Remote server returned an error: (403) forbidden" on Twitter auth using OAuth1Authenticator

$
0
0

//Twitter with OAuth1
var auth = new OAuth1Authenticator(
consumerKey: "using twitter Consumer API keys",
consumerSecret: "using twitter Consumer API secret keys",
requestTokenUrl: new Uri("https://api.twitter.com/oauth/request_token"),
authorizeUrl: new Uri("https://api.twitter.com/oauth/authorize"),
accessTokenUrl: new Uri("https://api.twitter.com/oauth/access_token"),
callbackUrl: new Uri("http://www.website.com.")
);

            auth.AllowCancel = true;
            // auth.ShowUIErrors = false;
            // If authorization succeeds or is canceled, .Completed will be fired.
            auth.Completed += (s, eventArgs) =>
            {
                // We presented the UI, so it's up to us to dismiss it.
                if (eventArgs.IsAuthenticated)
                {
                    //Utilities.userDetailsTW = new UserDetailsTW();
                    //Utilities.userDetailsTW.Token = eventArgs.Account.Properties["oauth_token"];
                    //Utilities.userDetailsTW.TokenSecret = eventArgs.Account.Properties["oauth_token_secret"];
                    //Utilities.userDetailsTW.TwitterId = eventArgs.Account.Properties["user_id"];
                    //Utilities.userDetailsTW.Name = eventArgs.Account.Properties["screen_name"];
                    //AccountStore.Create().Save(eventArgs.Account, "Twitter");
                }
                else    
                {
                    Console.WriteLine("failed");
                }
            };

Barcode Scanner / Reader in Xamarin Forms ?

$
0
0

Hi,

I have used Zxing.Net.Mobile for barcode scanning . But I found when using with MVVM pattern & scanner view page, performance & result is not good.

Any tips to improve the performance or any good alternative libraries.

Regards
Ajit

How to costum total renderer button? i want render 5 button only

How to make sapce in TabbedPage on top?

$
0
0

Hi, I'm trying to make space in TabbedPage on top. I created CustomTabbedPageRendererCS. But i don't know how do i coding.

public class CustomTabbedPageRenderer : TabbedPageRenderer
    {
        protected override void OnLayout(bool changed, int l, int t, int r, int b)
        {
            InvertLayoutThroughScale();
            base.OnLayout(changed, l, t, r, b);
        }

        private void InvertLayoutThroughScale()
        {

        }
    }

I want make TabbedPage like this picture. What should i use code? Thanks.


Images not loading on localhost SSL...

$
0
0

Hi i am running dot net core on localhost with self-signed certificate for development. I've followed this guide
https://docs.microsoft.com/en-us/xamarin/cross-platform/deploy-test/connect-to-local-web-services

However - images do not seem to be working. I am using FFImageLoading and i'm getting SSL exceptions. Any ideas how to resolve this please??

2020-11-26 21:46:46.163829+0000 MyApp.iOS[3687:143593] Image loading failed: https://localhost:5001/Uploads/ImagePath.png
FFImageLoading.Exceptions.DownloadAggregateException: One or more errors occurred. (The SSL connection could not be established, see inner exception.) (The SSL connection could not be established, see inner exception.) (The SSL connection could not be established, see inner exception.) (The SSL connection could not be established, see inner exception.) ---> System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception. ---> System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception. ---> Mono.Security.Interface.TlsException: CertificateUnknown

Apple reject my app "developer rejected"

$
0
0

Hello
I was struggling to upload my app in the past 3 months but i had no luck , i got to contact with apple developer and he told me few things to change after i did the update and uplode it i got this notfaction "developer rejected" could anyone tell what to do

How to prevent firing of event multiple times on rapid click of a button in Xamarin forms

$
0
0

How can I avoid invoking of the same event multiple times when a button is clicked rapidly.

Below is the code: I've created a Custom Delegate Command as below

View Model

namespace TestProject.ViewModels
{
    public class TestViewModel 
    {

        public CustomDelegateCommand MenuButtonClickCommand { get; set; }


        public TestViewModel()
        {
          MenuButtonClickCommand = new CustomDelegateCommand (async () => await ShowMenuAction());
        }


        private async Task ShowMenuAction()
        {
            //await some stuff
        }
    }
}

CustomDelegateCommand.cs

public class CustomDelegateTimerCommand : DelegateCommand
{
        public CustomDelegateTimerCommand(Action executeMethod, Func<bool> validateMethod, Action onBusy = default(Action)) : base(executeMethod)
        {
            BackgroundTaskWaitHandle = new EventWaitHandle(true, EventResetMode.ManualReset);
            _validateMethod = validateMethod;
            _onBusy = onBusy;
        }

}

The problem I'm facing is whenever a user clicks on the button rapidly, the menu list popup is opening multiple times. I have lot of commands in my project and I need a solution that would work globally.

I tried to resolve the issue like below using ObservesCanExecute() but I don't like the idea of creating a separate variable for every command as I've a lot of commands in my project and I don't want the button to go in to disabled state when CanExecute = false.

ViewModel

MenuButtonClickCommand = new CustomDelegateCommand (async () => await ShowMenuAction().ObservesCanExecute(() => CanExecute );

private async Task ShowMenuAction()
        {
            CanExecute = false;

            //await some stuff

            CanExecute = true;
        }

Any help is much appreciated!

Ad-version with the possibility to "upgrade"

$
0
0
Hello

Is there a sample available how to use Ads but with the possibility zo upgrade to a "non-ad-version" within the same app?

Do I have to do this with In-App-Purchases?

Thanks

Dominik

How can I run a service from the Boot?

$
0
0

I need to run a service when the phone is Off and then you turn it On

Viewing all 89864 articles
Browse latest View live


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