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

write in Mycode.cs page to type in a label in MyDesign.xaml page

$
0
0

I have a class C# file called Mycode.cs
and
I have a XAML page called MyDesign.xaml having a Label in it

What code should I write in Mycode.cs page to type in the label belonging to a completely different page?


Xamarin Forms - Android keyboard entry going to unexpected page

$
0
0

I have a situation where typed text doesn't go to the currently displayed page.

See the sample code below.

When the TestPage appears, click in Entry A to give it focus.
Then click the Click Me button.

The new page appears as you'd expect.
Now start typing on your physical keyboard (on my emulator the soft keyboard will appear as I type)
As Entry B does not have focus, the typed letters don't appear in Entry B.
Hit the Back button to dismiss the keyboard.
Hit the Back button to dismiss the new page.

Now we're back to TestPage, and strangely the text entered via the keyboard is now in Entry A.

It seems strange to me that keyboard entry would go to the page behind. This behaviour can also be demonstrated with two pages in a TabbedPage, so if Tab 1 contains an entry, give it focus. Then select Tab 2 and then type, go back to Tab 1, and observe the typed text is in that entry.

Is this expected? Is there an easy way I can prevent this behaviour?

I'm using VS2019, and Xamarin Forms v4.6. Running with an Android Emulator with API28.

public class TestPage : ContentPage
{
    public TestPage()
    {

        StackLayout stackLayout = new StackLayout();
        Entry entry = new Entry() { Placeholder = "Entry A"};
        Button button = new Button() { Text="Click Me"};
        stackLayout.Children.Add(entry);
        stackLayout.Children.Add(button);
        Content = stackLayout;

        button.Clicked += Button_Clicked;
    }

    private async void Button_Clicked(object sender, EventArgs e)
    {
        ContentPage page = new ContentPage();
        page.Content = new Entry() { Placeholder = "Entry B"};
        await Navigation.PushModalAsync(new NavigationPage(page));
    }
}

ccavenue payment gateway integration with Xamarin forms

$
0
0

ccavenue payment gateway integration with Xamarin forms

Old shared project open in VS2019 missing Xamarin.Forms in "Add new item" dialog

$
0
0

Hi,

I use VS2017 created a shared xamarin.forms project, today i installed the latest version of vs2019 and all the related SDK for Xamarin.forms
Use the new vs2019 to open the share project which created in vs2017, clean all and rebuild and make the apk file, test the new apk in my phone, seems everything looks good.

But when i click add new item, in the dialog i can't see the Xamarin.Forms in the left panel list

And when i created a new xamarin.forms project with vs2019, i can see the Xamarin.Forms in the Create new item dialog

Can someone tell me why? How to resolve this issue? My old shared project only contain Android project, no IOS and winPhone project, seems there is no share project in vs2019, do we need to change the shared project to normal one? How to change that?

Thanks inadvance!

Entiry Custom Renderer Trigger not fire

$
0
0

Hi everybody,

I have extendedentry and custom renderer classes

` public class ExtendedEntryRenderer : EntryRenderer
{

    /// <summary>
    /// Called when [element changed].
    /// </summary>
    /// <param name="e">The e.</param>
    protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
    {
        base.OnElementChanged(e);


        if (Control != null)
        {
            Control.Click += (sender, evt) =>
            {
                var nativeEditText = (global::Android.Widget.EditText)Control;

                nativeEditText.SetSelectAllOnFocus(true);

                new Handler().PostDelayed(delegate
                 {
                     Control.InputType = 0;
                     try
                     {
                         InputMethodManager inputMethodManager = Control.Context.GetSystemService(Android.Content.Context.InputMethodService) as InputMethodManager;
                         if (inputMethodManager != null)
                         {
                             inputMethodManager.HideSoftInputFromWindow(Control.WindowToken, HideSoftInputFlags.None);
                         }
                     }
                     catch (Exception Ex)
                     {

                     }
                 }, 300L);
            };


            // Hide soft input keyboard
            Control.FocusChange += (sender, evt) =>
            {
                // Select all on entry focus
                var nativeEditText = (global::Android.Widget.EditText)Control;

                nativeEditText.SetSelectAllOnFocus(true);

                new Handler().PostDelayed(delegate
                 {
                     Control.InputType = 0;
                     try
                     {
                         InputMethodManager inputMethodManager = Control.Context.GetSystemService(Android.Content.Context.InputMethodService) as InputMethodManager;
                         if (inputMethodManager != null)
                         {
                            inputMethodManager.HideSoftInputFromWindow(Control.WindowToken, HideSoftInputFlags.None);
                         }
                     }
                     catch (Exception Ex)
                     {

                     }
                 }, 300L);



            };
        }

    }

}`

`public class ExtendedEntry : Entry
{

}`

And my XAML file is like this:

`
<Entry.Triggers>




</Entry.Triggers>

            </local:ExtendedEntry>`

Trigger isnt work.

But when i change normal entry control like this:

`
<Entry.Triggers>




</Entry.Triggers>

            </Entry>`

Trigger is work.

Where did i wrong?

Thanks.

Why doesn't Font Awesome display for iOS apps using Xamarin Forms?

$
0
0

I'm trying to add font awesome icons to my tabbed page tabs. I've followed what I believe are the correct steps to be able to configure display font awesome icons for Xamarin.forms applications but for some reason the icons display for the android app but not the iOS app.

I first added the font awesome .ttf files to the android Assets folder and the iOS Resources folder:

Next I updated the Info.plist file for iOS in order to include the .ttf files from Font Awesome:

Then I configured use of the Font Awesome icons in App.xaml:

Finally I added the needed icons to the their tabs:

Different Android API causes layout problems

$
0
0

VS 2019, latest updates. So far only doing Android, but am wondering if I will run into the same problem for other OS's. When I deploy to the Android Emulator - Pixel 3a Pie 9.0 - API 28 (Android 10.0 - API 29), everything lines up nicely. When I deploy to my phone, Samsung SM-G935V (Android 8.0 - API 26), everything is off. Some lines, with a label, and entry widgets, the label is wrapped to two lines. The entry's on the bottom do not show (off the screen).

So, what should I do to try to fix this? How should I proceed (what should I be looking at\reading), so that I can adjust for the different versions of Android, and different android phones? Is my emulator version to high (but if I code for a lower version of Android, what happens when an install is done on a higher version)?
Thanks for any help or direction.

Pixel 2 Q 10.0 - API29: Access to Downloads folder denied

$
0
0

Hello,
My Xamarin.forms program allows the user to choose a photo from the Downloads folder and then import that photo into an SQLite database.
Since installing the Pixel 2 Q 10.0 - API29 emulator, I got an error message: Downloads: Access Denied. The program therefore cannot access the photo, and the photo is not updated in the database. I specify that it worked perfectly with the Pixel 2 Pie 9.0 - API 28 emulator.
I know Google has made some security changes, but what changes do you need to make in the Xamarin.forms program to get permission to access the Downloads folder?
Thank you for your reply.


The InitializeComponent() takes time

$
0
0

i have a Tabbed view like whatsup and the Main View is defined like this

<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage
    x:Class="WhatsApp.Views.MainView"
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:views="clr-namespace:WhatsApp.Views"    
    Title="Trova"  NavigationPage.HasBackButton="False"  >

    <TabbedPage.Padding>
        <OnPlatform x:TypeArguments="Thickness" iOS="0, 20, 0, 0" />
    </TabbedPage.Padding> 
    <views:SearchMain  BackgroundColor="Transparent"/>
    <views:MatchesView />
    <views:ChatsView BackgroundColor="Transparent"  />
    <views:ViewsLikes BackgroundColor="Transparent" /> 
</TabbedPage>

The InitililizeComponent takes time ,

  try
            {
                InitializeComponent();
            }
            catch (Exception ex)
            {
                throw ex;
            }

i placed a try catch to check if there is no exception in the xaml.

What could be a problem

OxyPlot not working in Xamaron.Forms.iOS

$
0
0

Hello,
My oxyplot chart works on Android only, on iOS nothing happens.
xmlns:oxy="clr-namespace:OxyPlot.Xamarin.Forms;assembly=OxyPlot.Xamarin.Forms"> <oxy:PlotView x:Name="appChart" VerticalOptions="Center" HorizontalOptions="Center" />
Code behind is simple chart with 2 lines in AppDelegate.cs:
global::Xamarin.Forms.Forms.Init(); OxyPlot.Xamarin.Forms.Platform.iOS.PlotViewRenderer.Init();

I move OxyPlot.Xamarin.Forms.Platform.iOS.Forms.Init() before global::Xamarin.Forms.Forms.Init(), but again blank screen.
No errors... Can you help me?

How to add validation for customised entry

$
0
0

Hi,

I am using customised entry. I need to implement validation for customised entry in which field shoud take only numbers. No alphabets , no special character, no dots are allowed.

Can anyone help me how to implement validation for customised entry

ccavenue payment gateway integration with Xamarin forms

$
0
0

ccavenue payment gateway integration with Xamarin forms

FreshMVVM gives me "the impulse" to write View code inside the ViewModel, is it normal?

$
0
0

Hello, the title is a bit clickbaity, made as a joke :smile:

I'm not a professional, yet, but hoping to become one pretty soon!
I have 3 years of hobbistic experience with C++, but never designed nor developed a GUI.

Always used Visual Studio so, here I am with Xamarin.Forms and C#.

Now, I'm developing an offline Diet Diary for my own purposes and also as a portfolio app.

I learned just the basics, then I looked for frameworks and found FreshMVVM (also MVVM Cross and Prism) and chosen it for its semplicity as my application is not complex.

The fact is that FreshMVVM allows me to access the View directly from the ViewModel, so I designed my application to be ViewModel centric, where the View will contain XAML code only, no C# at all.

This is against the MVVM pattern. I'm experienced enough to see that this will not have any impact on my application, due to its simplicity, but that's not how the MVVM pattern works.

It's better to show you how the application will work, more or less.

This is an example so it has less pages than the real application has.

3 pages, 3 View Models

Page View ViewModel Model
Food X X X
FoodList X X
Meal X X X

Food Model

public int Type { get; set; }
public string Name { get; set; }
public int KCal { get; set; }

Food ViewModel

  • VIEW mode, where data are readonly
  • EDIT mode, where data can be modified
  • CREATE mode, like EDIT mode but with empty data
  • Loads/Stores the Model to the DB

FoodList View

  • Shows the list of Foods
  • Has UI to filter the list, like search by name, including/excluding types etc.

FoodList ViewModel

  • VIEW mode, where you can see the list of food, tapping on them opens the Food View in VIEW mode
  • SELECTION mode, multiple selection of food items that will be added to the Meal
  • Handles the filtering of the View

Meal Model

public DateTime Day { get; set; } // when did we eat?
public int Type { get; set; }
public List<Food> FoodEaten { get; set; }

Meal ViewModel

  • VIEW mode, shows the data as readonly
  • EDIT mode, data is modifiable
  • CREATE mode, the meal doesn't exists yet
  • Loads/Stores the Model to the DB

Meal View
Shows the data

The fact is that FreshMVVM has methods that controls the navigation between the pages through the ViewModel, also allowing to pass data between them, so I can do this:

// The parameters are pseudocode to show how the data is transfered

// Sends to the Food ViewModel the food's data + how it should 
CoreMethods.PushPageModel<FoodPageModel>(open in VIEW mode, food to show);show them

// From the FoodList ViewModel we return to the Meal ViewModel with the list of selected food item that we ate
CoreMethods.PopPageModel(return selected foods to the Meal);

The navigation is more or less like this:

Master-Detail page -> FoodList in View mode <--> Food (all modes)
Master-Detail page -> Meal in View or Create mode <--> FoodList in Selection mode <--> Food (all modes)

The View is being controlled by the ViewModel through properties like IsEditing or IsSaving and stuff like that.
But how do I tell the View in which mode I need to be? Because this changes how the Toolbar is populated, which items it has and which not.
For instance in VIEW mode, I can only start editing, so I add 1 toolbaritem with the EditCommand. In EDIT/CREATE mode I have Save/Cancel toolbar items etc.

Honestly I don't know how to do it without passing by the ViewModel itself, and at that point why should I use C# in the View?

How Handle Start/End Call events

$
0
0

Hi there,

I´m premising that I´m new with mobile development and actually I´m developing an App using Xamain.Forms and Xamarin.Essentials

Now my goal is to start a call programmatically and handle the events of start call and end call.

To start the call I´m using Xamarin.Essentials PhoneDialer and it is not a problem, but I cannot found the way to handle the events of that call, and in particular StartOfCall and EndOfCall.

Somebody can help ?

Thank you in advance

Profile images

$
0
0

Good night guys, I have a chat application where each user has their image. The aplicitvo works offline and the users' images are in the local bank (SQLite) in BASE64.

To display these images in the chat list and other elements what is the best way?
1) Load the images into memory by converting BASE64 to an image.
2) Generate the images physically in an APP folder and use the physical path.
3) Another suggestion.

If anyone has been through this scenario, please give me a light.


How to upload files to S3 bucket using access token from sign-in

$
0
0

I've set up login endpoint in AWS which returns an access token in the response. I've stored this token in Application.Current.Properties

I want to use the access token as I need the user to be signed into the app to be allowed to upload images.

I've set up an S3 bucket, but need to know how I can configure a new s3 client to upload to this bucket
e.g:

    var s3Client = new AmazonS3Client("appClientId",
                "appClientSecret",
                Application.Current.Properties["access_token"].ToString()); // how to configure this part?

    var images = GetIPhoneImagesFromFolder();
        foreach (var image in images)
        {                
            var bArray = ImageSourceToBytes(image.imageSource);                
            var base64String = Convert.ToBase64String(bArray);

            try
            {
                byte[] bytes = Convert.FromBase64String(base64String);

                using (s3Client)
                {
                    var request = new PutObjectRequest
                    {                          
                        CannedACL = S3CannedACL.PublicRead,
                        Key = string.Format("MyFolder/{0}", image.imageSource)
                    };
                    using (var ms = new MemoryStream(bytes))
                    {
                        ms.Position = 0;
                        request.InputStream = ms;
                        s3Client.PutObjectAsync(request);
                    }
                }
            }

How to raise click event on nested listview ?

$
0
0

Hello all,

Can anyone please help me to understand how to call nested item click event in prism?

Insecure HttpClientHandler works in iOS but not in Android - Connection Reset by Peer

$
0
0

Hello

I am developing a cross platform app for Android and iOS.
I am using an insecure HttpClientHandler for a HTTPS connection with my webservice.

It is a strange issue. I can connect to the web service on my machine with both Android device and iOS emulator but with another server, the connection only works with iOS.

With Android , I get the following error:
The SSL connection could not be established, see inner exception.
Inner exception ->
Unable to read data from transport connection. Connection reset by peer. error code 10054.

I have already checked that both my machine and server have a valid SSL certificate assigned to the required port.
The service running is the same on both. iOS app works, Android doesn't.

Any ideas??

why navigation between pages in xamarin forms is slow on Android

Xamarin Forms: How to capture the webview video/audio play time?

$
0
0

I am using webview for playing video and audio in my projects like the below screenshot.

enter image description here

I need to capture the video/audio playtime when going back from that page. I research about this but didn't get anything useful.

Is there any way to fetch the video/audio playtime?

Update

Video: XAML

<local:VideoWebview
    x:Name="web_view"
    HorizontalOptions="FillAndExpand"
    VerticalOptions="FillAndExpand">
</local:VideoWebview>

XAML.CS

if (Device.RuntimePlatform == Device.iOS)
{
    Device.BeginInvokeOnMainThread(() =>
{
    web_view.Url = videourl;
});
}
else
{
    web_view.Source = videourl;
}

Audio: XAML

<WebView 
    x:Name="web_view"
    HorizontalOptions="FillAndExpand"
    VerticalOptions="FillAndExpand">
</WebView>

XAML.CS

web_view.Source = audiourl;

Sample Video URL: https://player.vimeo.com/video/434126696?api=1&player_id=player1

Sample Audio URL: http://catholic-brain.s3.amazonaws.com/qa/dc/cbrain-app/files/doc-lib/2017/08/16/11/21/59/604/head/Catholic-brain-01-The-Rosary-Song.mp3

I am using a custom renderer in ios video webview for the transparent background.

public class VideoWebviewRenderer : ViewRenderer<VideoWebview, WKWebView>
{
    WKWebView wkWebView;

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

        if (Control == null)
        {
            WKWebViewConfiguration configuration = new WKWebViewConfiguration();
            configuration.AllowsInlineMediaPlayback = true;
            wkWebView = new WKWebView(CGRect.Empty, configuration);
            //transparent background
            wkWebView = new WKWebView(CGRect.Empty, configuration);
            wkWebView.BackgroundColor = UIColor.Clear;
            wkWebView.ScrollView.BackgroundColor = UIColor.Clear;
            wkWebView.Opaque = false;

            if (Element.Url != null)
            {
                wkWebView.LoadRequest(new NSUrlRequest(new NSUrl((Element).Url)));
            }
            SetNativeControl(wkWebView);
        }
    }

    protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        if (e.PropertyName.Equals(nameof(Element.Url)))
        {
            wkWebView.LoadRequest(new NSUrlRequest(new NSUrl((Element).Url)));
        }
    }

    public override void Draw(CGRect rect)
    {
        base.Draw(rect);

        Control.Frame = rect;
    }
}
Viewing all 79144 articles
Browse latest View live


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