Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

How to make a Toast using Acr Userdialogs?

SreeeeSreeee INMember ✭✭✭✭✭

I tried like below, but getting an unhandled exception.

    ToastEvent toastEvent = new ToastEvent();
        var toastConfig = new ToastConfig(toastEvent,"Toasting...","");
        toastConfig.SetDuration(3000);

        UserDialogs.Instance.Toast(toastConfig);

Thanks in advance :)

Answers

  • CharwakaCharwaka INMember ✭✭✭✭✭

    @Sreeee said:
    I tried like below, but getting an unhandled exception.

      ToastEvent toastEvent = new ToastEvent();
            var toastConfig = new ToastConfig(toastEvent,"Toasting...","");
            toastConfig.SetDuration(3000);
    
            UserDialogs.Instance.Toast(toastConfig);
    

    Thanks in advance :)

    What is Inner Exception, can you paste or attach output log ?

  • SreeeeSreeee INMember ✭✭✭✭✭

    @Charwaka said:

    @Sreeee said:
    I tried like below, but getting an unhandled exception.

        ToastEvent toastEvent = new ToastEvent();
            var toastConfig = new ToastConfig(toastEvent,"Toasting...","");
            toastConfig.SetDuration(3000);
    
            UserDialogs.Instance.Toast(toastConfig);
    

    Thanks in advance :)

    What is Inner Exception, can you paste or attach output log ?

    06-14 14:13:40.499 D/OpenGLRenderer( 1450): endAllStagingAnimators on 0xb9ae71a0 (RippleDrawable) with handle 0xb9b5bac0
    06-14 14:13:40.544 W/View    ( 1450): requestLayout() improperly called by md5b60ffeb829f638581ab2bb9b1a7f4f3f.ScrollViewContainer{197e6e8 V.E..... ......ID 0,0-480,816} during layout: running second layout pass
    06-14 14:13:43.186 D/Mono    ( 1450): Assembly Ref addref Business_App[0xb8ad3d70] -> Acr.UserDialogs.Interface[0xb8ab66d0]: 3
    06-14 14:13:43.186 D/Mono    ( 1450): Assembly Ref addref Business_App[0xb8ad3d70] -> Acr.UserDialogs[0xb8ab5708]: 3
    An unhandled exception occured.
    
  • AllanRitchieAllanRitchie CAInsider, University ✭✭✭

    What's the Init call you're using?

  • CharwakaCharwaka INMember ✭✭✭✭✭

    @Sreeee said:

    @Charwaka said:

    @Sreeee said:
    I tried like below, but getting an unhandled exception.

      ToastEvent toastEvent = new ToastEvent();
            var toastConfig = new ToastConfig(toastEvent,"Toasting...","");
            toastConfig.SetDuration(3000);
    
            UserDialogs.Instance.Toast(toastConfig);
    

    Thanks in advance :)

    What is Inner Exception, can you paste or attach output log ?

    06-14 14:13:40.499 D/OpenGLRenderer( 1450): endAllStagingAnimators on 0xb9ae71a0 (RippleDrawable) with handle 0xb9b5bac0
    06-14 14:13:40.544 W/View ( 1450): requestLayout() improperly called by md5b60ffeb829f638581ab2bb9b1a7f4f3f.ScrollViewContainer{197e6e8 V.E..... ......ID 0,0-480,816} during layout: running second layout pass
    06-14 14:13:43.186 D/Mono ( 1450): Assembly Ref addref Business_App[0xb8ad3d70] -> Acr.UserDialogs.Interface[0xb8ab66d0]: 3
    06-14 14:13:43.186 D/Mono ( 1450): Assembly Ref addref Business_App[0xb8ad3d70] -> Acr.UserDialogs[0xb8ab5708]: 3
    An unhandled exception occured.

    are you using listview with setFastScrollEnabled(true)

  • CharwakaCharwaka INMember ✭✭✭✭✭

    @Sreeee said:
    I tried like below, but getting an unhandled exception.

      ToastEvent toastEvent = new ToastEvent();
            var toastConfig = new ToastConfig(toastEvent,"Toasting...","");
            toastConfig.SetDuration(3000);
    
            UserDialogs.Instance.Toast(toastConfig);
    

    Thanks in advance :)

    Device.BeginInvokeOnMainThread(() =>
    {
    // show toast here
    });

  • SreeeeSreeee INMember ✭✭✭✭✭
    edited June 2018

    @Charwaka Tried like below, but getting the same exception :'(

    Device.BeginInvokeOnMainThread(() =>
    {
    ToastEvent toastEvent = new ToastEvent();
            var toastConfig = new ToastConfig(toastEvent,"Toasting...","");
            toastConfig.SetDuration(3000);
    
            UserDialogs.Instance.Toast(toastConfig);
    });
    

    I am trying to show a toast when a button click, no listview.

  • I know this is an older post but I'll leave a reply in case someone Googles in.

    I put Toast configuration in MainActivity of the Xamarin Forms Android project and it gets applied to both Android and iOS apps (at least on dev devices; not yet released to App Stores).

    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
        protected override void OnCreate(Bundle bundle)
        {
            ...
            UserDialogs.Init(this);
            ToastConfig.DefaultActionTextColor = Color.White;
            ToastConfig.DefaultBackgroundColor = Color.CadetBlue;
            ToastConfig.DefaultDuration = TimeSpan.FromSeconds(4.0);
            ToastConfig.DefaultPosition = ToastPosition.Bottom;
            ...
        }
    

    In my view model:

        public StoreSelectorViewModel() : this (new DialogService())
        {
        }
    
        public StoreSelectorViewModel(IDialogService dialogService)
        {
            _dialogService = dialogService;
    
            ...
        }
    

    Actually using it in the view model:

        private void StoreSelected(StoreInfo selectedStore)
        {
            ...
            _dialogService.ShowToast($"Your selected store is now {selectedStore.Name}");
        }
    

    The Interface:

    public interface IDialogService
    {
        Task ShowAlertAsync(string message, string title, string buttonLabel);
    
        void ShowToast(string message);
    }
    

    The default implementation:

    public class DialogService : IDialogService
    {
        public Task ShowAlertAsync(string message, string title, string buttonLabel)
        {
            return UserDialogs.Instance.AlertAsync(message, title, buttonLabel);
        }
    
        public void ShowToast(string message)
        {
            UserDialogs.Instance.Toast(message);
        }
    }
    
Sign In or Register to comment.