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

Display rest api response in Grid Form

$
0
0

I have a rest api call where json response is as follows:

{
"message": "new msg",
"data": [
         {
        "name" : "john",
        "id" : "#123",
         "org": {
                     "uuid": "#Aeoc",
                     "dob": "1-1-89"
                    }
          },
         {
         "name" : "Thomas",
         "id" : "#45",
         "org": {
                      "uuid": "#HGBic",
                      "dob": "2-4-79"
                    }
           }
       ]
   }

I want to display only the data fields in the form of a grid. This is what I have tried --

{
     //De-serialize json. Works well.

     // create a grid in for loop.

     StackLayout layout = new StackLayout();
     foreach(var obj in data)
     {
                Grid grid = new Grid
                {
                    .......//more code on grid
                }
                layout.Children.Add(grid)
     }
 }

So, from the above code, only a single grid is displayed which contains the data for last fields in "data". (in above example-Thomas,#45). I have put breakpoints and noticed that the first entries are been overwritten by the next fields. Also, the number of fields in data entry vary dynamically.

How do I display separate grid for each entry.


Cross-browser native messaging (especially chrome) from Xamarin forms macOS

$
0
0

Hello,

As per my request on Stackoverflow which remained unanswered thus far ( https://stackoverflow.com/questions/60158354/cross-browser-cross-platform-native-messaging-using-xamarin-mac-c-sharp) , I would like to know if anyone managed to get a Xamarin Forms application to work with the Chrome native messaging API.

My problem occurred with the following message : "Error when communicating with the native messaging host."
My thought is that attaching to a running process caused the issue , as I used the running app path with grep, and put it in the host file.

Getting a way to have this work without build the program for full release would be appreciated, if this is indeed the issue.

Hopefully, someone already did an app which communicates with native messaging using Xamarin from macOS, and will share her or his knowledge here.

Thanks in advance.

using OnPlatform to set theme

$
0
0

Given that I have this ...

<Application.Resources>

</Application.Resources>

is it possible to change the included source based on platform something like ...

<ResourceDictionary.Source>
         <OnPlatform x:TypeArguments="x:Uri">
             <On Platform="iOS">Themes/LightTheme.xaml</On>
             <On Platform="Android">Themes/LightTheme.xam</On>
         </OnPlatform>
   </ResourceDictionary.Source>

this doesn't work it causes the dreaded InvalidOperationException

Thanks
KMV

Not able to access itemtapped event in CollectionView?

$
0
0

Hi,

I am not able to access the itemtapped event in collectionview.dont we have item tapped event in collectionview?...if its not their what should we use insted of that?

Thanks!

Button Visibility in xamarin forms

$
0
0

i have 20 buttons and need to make condition that if 1st button visibility is True remaining 19 button visibility will be False

Store audio file (.wav) in SQLite database

$
0
0

I am using sqlite-net-pcl as my database in my xamarin forms project.

This is my table to create text to label that audio:

[Table("SpeechRecTable")]
    [Serializable]
    public class SpeechRecTable
    {
        [PrimaryKey]
        public int Id { get; set; }
        public string Text { get; set; }
        public string Speech { get; set; }

        public override string ToString()
        {
            return string.Format("[User: Id={0}, Text={1}, Speech={2}]", Id, Text, Speech);
        }
    }

I still haven't used the "Speech" part of this.

Based on my research, I can store audio the same way you store images. I am new in xamarin an I am still 1 month in learning this. So I dont have any knowledge on how to do it. I still didn't find any good documentation for storing audio (.wav).

This is my code for audio recording, and it only lets me record 1 audio and when I record another the last recorded audio will be gone. I want to access all my recorded audio in another page with their specified text label.

            try
            {
                var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Microphone);

                //await DisplayAlert("Pre - Results wat", status.ToString(), "OK");
                if (!recorder.IsRecording)
                {
                    recorder.StopRecordingOnSilence = TimeoutSwitch.IsToggled;

                    RecEditor.IsEnabled = false;
                    PlayButton.IsEnabled = false;

                    //Start recording
                    var audioRecordTask = await recorder.StartRecording();

                    BtnDoneRec.IsEnabled = false;

                    await audioRecordTask;

                    PlayButton.IsEnabled = true;
                }

                else
                {
                    RecEditor.IsEnabled = true;
                    BtnDoneRec.IsEnabled = true;

                    //stop recording ...
                    await recorder.StopRecording();
                }

                if (status != PermissionStatus.Granted)
                {
                    status = await Utils.CheckPermissions(Permission.Microphone);
                    //await DisplayAlert("Results", status.ToString(), "OK");                   
                }
            }

            catch (Exception ex)
            {
                //blow up the app!
                await DisplayAlert("Error", ex.Message, "OK");
            }

This is the play button code:

            try
            {
                var filePath = recorder.GetAudioFilePath();

                if (filePath != null)
                {
                    player.Play(filePath);
                }
            }

            catch (Exception ex)
            {
                //blow up the app!
                await DisplayAlert("Error", ex.Message, "OK");
            }

I am using android for this project.

How to implement infinite scrolling in collection view ?

How to open other apps from xamarin forms

$
0
0

How to open other apps from xamarin forms ?
or
How to open other apps from xamarin forms apps


Storing images in Sqlite and retriving

$
0
0

Hi,
Currently i working in storing images (ImageSource) in sqlite. I am reading files from local directory after that i trying to storing the images into sqlite but i can't able to store the images . can any one help me to store. also how to convert image source as bytes in xamarin.forms

Thanks

Sharing a link to the others through the twitter in xamarin forms?

$
0
0

Can anyone help me on this. How to Share a Add request link to the others through the Twitter in xamarin forms. Please help me.

Thanks in advance.

SetCurrentScreen is not working

$
0
0

Hi,

I am trying to use the SetCurrentScreen with Xamarin Forms but I am not getting anything logged in my Analytics

Here is my Android class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Firebase.Analytics;
using Jafaria;
using Xamarin.Forms;

[assembly: Xamarin.Forms.Dependency(typeof(Jafaria.Droid.GoogleFirebaseAnalytics))]
namespace Jafaria.Droid
{
    public class GoogleFirebaseAnalytics : IFirebaseAnalytics
    {
        // Event Analytics
        public void LogEvent(string eventId)
        {
            LogEvent(eventId, null);
        }

        public void LogEvent(string eventId, string paramName, string value)
        {
            LogEvent(eventId, new Dictionary<string, string>
            {
                {paramName, value}
            });
        }

        public void LogScreen(string screenName, string screenClass)
        {
            var fireBaseAnalytics = FirebaseAnalytics.GetInstance(Android.App.Application.Context);

            fireBaseAnalytics.SetCurrentScreen(new Android.App.Activity(), screenName, screenClass);
        }

        public void LogEvent(string eventId, IDictionary<string, string> parameters)
        {
            var fireBaseAnalytics = FirebaseAnalytics.GetInstance(Android.App.Application.Context);

            if (parameters == null)
            {
                fireBaseAnalytics.LogEvent(eventId, null);
                return;
            }

            var bundle = new Bundle();

            // foreach (var item in parameters)
            foreach (var param in parameters)
            {
                bundle.PutString(param.Key, param.Value);
            }

            fireBaseAnalytics.LogEvent(eventId, bundle);
        }
    }
}

and my Interface:

using System;
using System.Collections.Generic;
using System.Text;

namespace Jafaria
{
    public interface IFirebaseAnalytics
    {
        void LogEvent(string eventId);
        void LogEvent(string eventId, string paramName, string value);
        void LogEvent(string eventId, IDictionary<string, string> parameters);

        void LogScreen(string screenName, string screenClass);
    }
}

then in my Page I am calling:

DependencyService.Get<IFirebaseAnalytics>().LogScreen(this.Title, this.Title);

Kindly help..

Thanks,
Jassim

IncrementalLoadingPage CollectionView

$
0
0

hi

Causes **synchronous **interference
And it makes the data load a lot

**void **method Works without problems

public class CategorieListViewModel : INotifyPropertyChanged
{
public ObservableCollection ListItems { get; set; }

    public ICommand LoadMoreDataCommand => new Command(GetNextPageOfData);

    public CategorieListViewModel(string NameEnSlug)
    {
        this.NameEnSlug = NameEnSlug;
        ListItems = new ObservableCollection<GetListProductByCategorieModel>();
    }

    private string NameEnSlug { get; set; }
    private int PageIndex { get; set; } = 0;



    bool isRefreshing;
    public bool IsRefreshing
    {
        get { return isRefreshing; }
        set
        {
            isRefreshing = value;
            OnPropertyChanged();
        }
    }
    async void GetNextPageOfData()
    {
        IsRefreshing = true;
        Initialize();
        IsRefreshing = false;
    }

    async void Initialize()
    {          
        var ProductForCat = BLL.GetListProductForCategorie(NameEnSlug, PageIndex + 1);
        if (ProductForCat != null && ProductForCat.Result.ProductByCategorie.Count > 0)
        {
            PageIndex++;

            foreach (var item in ProductForCat.Result.ProductByCategorie)
                ListItems.Add(item);

            DependencyService.Get<Plugin.Toast>().Show("page" + PageIndex + " add " + ProductForCat.Result.ProductByCategorie.Count);
        }         
    }

    #region INotifyPropertyChanged

    public event PropertyChangedEventHandler PropertyChanged;

    void OnPropertyChanged([CallerMemberName] string propertyName = null)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }

    #endregion
}

Is there a good XForms barcode scanning other than ZXing?

$
0
0

I was wondering if there is another good barcode scanning library to use for Xamarin.Forms other than ZXing by Redth. It seems ZXing last update was on 2018 and very well possibly might not be updated again. Since iOS launched its version 13 out I'm sure a lot of you know about the view tabbing issues that happened. This ZXing library also experienced the tabbing issue on the barcode view and has no override for us to use. There is a pull request sitting waiting but I dont think this project is abandoned (https://github.com/Redth/ZXing.Net.Mobile/pull/849).


Above is an example of the tabbing issue. If the user swipes down the tab will close and the app wont respond. There is a iOS override fix for this where it sets the control to fullscreen, but we cant access this for ZXing library.

UWP UI Colors (Tool Bar and Tabbed Page)

$
0
0

Hello,
I feel bad that my first post here will probably be stupidly simple but I can’t seem to find this one, so after a full day of looking around I decided to ask (and accept all criticism). Created a UWP application inside an already existing (Prism) Forms project, everything referenced to the Forms nicely, but editing the colors is not straightforward at all.
Specifically the Tool Bar (or Navigation Bar?, the red square) has this gray-ish color (from the Light Theme I presume) and I can’t seem to change it or the letters. Was looking around for a non hackish solution like changing the theme’s light color, even though I haven’t tried that to even see if it works. Also the “More” dot thing (the blue circle), is redundant, there is nothing to expand, can it go away?
Lastly in the tabbed page, the icons (purple square) are stacked on the left side and I cannot seem to find anything resembling its Column Definitions, Horizontal Options or the option of whatever structure it uses to align them in the center. Do I need a custom renderer for this one?
I have no code to show, since I don’t even know from where to edit these, the Xamarin docs had an example with SolidColorBrush for buttons but since most code I found uses x:Keys to reference the items, I don’t have intellisense on those and can’t try different things out.

Thanks for any answer on any on the above in advance!

Navigation back button accessibility name

$
0
0

If you have enabled the navigation page, with the back button (the "<" icon) and the title, when the screen reader focus is on the back button it read "unlabeled button". Is there a way to change is Accessibility name to a proper "back button" or whatever else? Either in Android and iOS


Xamarin Forms iOS Button Click Event is not firing when keyboard is open (XF 4.3.0)

$
0
0

Hey, I am posting a new question as a followup to this old question as instructed by @JoeHarvey_MSFT and @Charwaka

So, on iOS with an effect that affects the page layout, clicking on a button attached to the bottom of the page causes the entry unfocused event to block the button click event. This works correctly with a frame/label combo that emulates the button (thanks @AyalBelling ).

Below is sample XAML code (Use either BUTTON or FRAME CASE to check):

<Grid VerticalOptions="FillAndExpand">
    <ScrollView VerticalOptions="FillAndExpand">
        <StackLayout Padding="10, 20, 10, 60">
            <Label Text="Phone Number"
                   TextColor="{StaticResource PrimaryColorBase}"/>
            <Entry Placeholder="Add phone number..."
                   Text="{Binding PhoneNumber}"
                   PlaceholderColor="{StaticResource GrayColor}"
                   Keyboard="Telephone"/>

            <Label Text="Email"
                   TextColor="{StaticResource PrimaryColorBase}"/>
            <Entry Placeholder="Add email..."
                   Text="{Binding Email}"
                   PlaceholderColor="{StaticResource GrayColor}"
                   Keyboard="Email"/>
        </StackLayout>
    </ScrollView>

    <Grid HeightRequest="50"
           VerticalOptions="EndAndExpand">

         <!-- BUTTON CASE: Click fires unfocused event first and button click event is not firing on iOS -->
          <Button
            Text="Submit"
            HorizontalOptions="FillAndExpand"
            VerticalOptions="FillAndExpand"
            IsEnabled="{Binding IsDirty, Mode=TwoWay}"
            BackgroundColor="{StaticResource PrimaryColorBase}"
            TextColor="{StaticResource LightTextColor}"
            Margin="2"
            CornerRadius="4"
            Command="{Binding SubmitCommand}"/>

        <!-- FRAME CASE: Using frame instead of button to overcome button not firing click event when over the keyboard -->
        <Frame HasShadow="false"
               BackgroundColor="{StaticResource PrimaryColorBase}"
               OutlineColor="{StaticResource PrimaryColorBase}"
               IsEnabled="{Binding IsDirty, Mode=TwoWay}"
               Margin="2" Padding="0"
               CornerRadius="4"
               HorizontalOptions="FillAndExpand"
               VerticalOptions="FillAndExpand">
            <Frame.GestureRecognizers>
                <TapGestureRecognizer Command="{Binding SubmitCommand}" NumberOfTapsRequired="1" />
            </Frame.GestureRecognizers>

            <Label TextColor="{StaticResource LightTextColor}" Text="Submit"
                   HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"/>
        </Frame>

    </Grid>
</Grid>

iOS effect applied on page that changes page layout:

[assembly: ExportEffect(typeof(Company.Mobile.iOS.Effects.ResizeOnKeyboardEffect), "ResizeOnKeyboardEffect")]
namespace Company.Mobile.iOS.Effects
{
    public class ResizeOnKeyboardEffect : PlatformEffect
    {
        NSObject observerHideKeyboard;
        NSObject observerShowKeyboard;

        protected override void OnAttached()
        {
            if (Element is VisualElement)
            {
                observerHideKeyboard = UIKeyboard.Notifications.ObserveWillHide(OnKeyboardNotification);
                observerShowKeyboard = UIKeyboard.Notifications.ObserveWillShow(OnKeyboardNotification);
            }
        }

        protected override void OnDetached()
        {
            if (Element is VisualElement)
            {
                observerHideKeyboard.Dispose();
                observerShowKeyboard.Dispose();
            }
        }

        void OnKeyboardNotification(object sender, UIKeyboardEventArgs args)
        {
            var element = (VisualElement)Element;
            var frameBegin = args.FrameBegin;
            var frameEnd = args.FrameEnd;
            var bounds = element.Bounds;
            var newBounds = new Rectangle(bounds.Left, bounds.Top, bounds.Width, bounds.Height - frameBegin.Top + frameEnd.Top);
            element.Layout(newBounds);
        }
    }
}

Please feel free to file any official bug reports if needed, or maybe I could do it myself under your blessed guidance.

Thanks for your time and great efforts all!

Shell - IsVisible

$
0
0

I am new to using Shell and Xamarin forms in general. I watched a presentation where shell items could be hidden using the property IsVisible but I can't find any documentation on that feature. I have installed the latest pre-release NuGet to see if it was on the up and coming but it's not coming up via IntelliSense in the XAML editor or when building my shell in c sharp there are is no IsVisible property.

I need to have a group of views with top tabs that can only be navigated to programmatically, I am open to other solutions to this use case.

Listview Selected Item Background Color

$
0
0

Is it possible to set the ListView selected item background color? Right now on IOS its gray and I want it to be transparent if possible.

How to stop iFrame from opening in the browser on the webview loading.

$
0
0

Hi, I have a Xamarin.Forms app with a webview that load some content from a wordpress rest API. Everythings works for android but for ios when I have an iFrame on the page (youtube video), it will open the youtube video automatically in the browser. If I press the back button it will show the webview content but it won't show the youtube videos? Does anyone know what could cause that problem?

X.Forms Android Button OnPress Visual Bug

$
0
0

Hey guys,

I'm really frustrated and require some help from you. I'm not really new at Xamarin, but some things won't get in my brain. Maybe I haven't understood the entire logic so far.

But, my problem is: I've been adding a Button to the content page and all were working fine. So, I had to change the background color and now it's messed up! When I click the button, it shows WHILE the press event is invoked, a small visible rectangle with the 0.25 scale of the entire button on the top left of the button.

Can someone help me? I've made a screenshot WHILE PRESSING THE BUTTON here:

Note: BEFORE changing the background color, all has been working fine. AFTER setting the background color, the color gets changed well and is correct but the PRESS/CLICK/ACTIVE state of the button shows a small - unrequired - rectangle on the top left of the button.

Thankful for every answer.

Kind regards,
Dominik G.

Viewing all 89864 articles
Browse latest View live


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