Include icon with DisplayPromptAsync

ChuckieAJ 86 Reputation points
2021-02-21T18:22:02.707+00:00

Is it possible to add support for including an image when using DisplayPromptAsync? I small image like on all the popups we already get from the Mac?

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,312 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 70,646 Reputation points Microsoft Vendor
    2021-02-22T02:55:37.153+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    No, it cannot be achieved, if you want to add an icon in the popup page, you should create a custom popup page.

    You can use Rg.Plugins.Popup this plugin to achieve it.

    https://github.com/rotorgames/Rg.Plugins.Popup

    Here is my running screenshot.

    70441-image.png

    Here is my popup demo code.

       <pages:PopupPage  xmlns="http://xamarin.com/schemas/2014/forms"  
                    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"  
                     xmlns:pages="clr-namespace:Rg.Plugins.Popup.Pages;assembly=Rg.Plugins.Popup"  
                     xmlns:animations="clr-namespace:Rg.Plugins.Popup.Animations;assembly=Rg.Plugins.Popup"  
                           
                    x:Class="App52.Page1">  
           <pages:PopupPage.Animation>  
               <animations:ScaleAnimation   
                   PositionIn="Center"  
                   PositionOut="Center"  
                   ScaleIn="1.2"  
                   ScaleOut="0.8"  
                   DurationIn="400"  
                   DurationOut="300"  
                   EasingIn="SinOut"  
                   EasingOut="SinIn"  
                   HasBackgroundAnimation="True"/>  
           </pages:PopupPage.Animation>  
           <!--You can use any elements here which are extended from Xamarin.Forms.View-->  
           <Frame CornerRadius="20" WidthRequest="250" VerticalOptions="Center" HorizontalOptions="Center">  
           <StackLayout   
               VerticalOptions="Center"   
               HorizontalOptions="Center"   
               Padding="5">  
                   <Grid>  
                       <Grid.ColumnDefinitions>  
                           <ColumnDefinition Width="*"/>  
                           <ColumnDefinition Width="4*"/>  
                       </Grid.ColumnDefinitions>  
                       <Image Source="hamburger.png" WidthRequest="30" HeightRequest="30" Grid.Column="0"></Image>  
                       <Label Text="Question" FontSize="Subtitle" FontAttributes="Bold" Grid.Column="1"/>  
         
                   </Grid>  
                   <Label Text="What is your name?" FontSize="Body" />  
                   <Entry x:Name="MyEntry"></Entry>  
                   <Button Text="OK" Clicked="Button_Clicked"></Button>  
           </StackLayout>  
           </Frame>  
       </pages:PopupPage>  
    

    Here is popup layout's background code. When popup was closed, we can use MessagingCenter to transfer data to the previous page.

       using Rg.Plugins.Popup.Extensions;  
       using System;  
       using System.Collections.Generic;  
       using System.Linq;  
       using System.Text;  
       using System.Threading.Tasks;  
         
       using Xamarin.Forms;  
       using Xamarin.Forms.Xaml;  
         
       namespace App52  
       {  
           [XamlCompilation(XamlCompilationOptions.Compile)]  
           public partial class Page1 : Rg.Plugins.Popup.Pages.PopupPage  
           {  
               public Page1()  
               {  
                   InitializeComponent();  
               }  
         
               private async void Button_Clicked(object sender, EventArgs e)  
               {  
                   MessagingCenter.Send<App, string>((App)App.Current, "OneMessage", MyEntry.Text);  
                   
         
                   await Navigation.PopPopupAsync();  
               }  
           }  
       }  
    

    We can receive the data in the previous page.

       public partial class MainPage : ContentPage  
           {  
               public MainPage()  
               {  
                   InitializeComponent();  
         
                   MessagingCenter.Subscribe<App, string>(App.Current, "OneMessage", (snd, arg) =>  
                   {  
                       Device.BeginInvokeOnMainThread(() => {  
                           //Navigation.PushAsync(new NavigationPage(new DetailsInfo(arg)));  
         
                           myLabel.Text = arg;  
                       });  
                   });  
               }  
         
               private async void Button_Clicked(object sender, EventArgs e)  
               {  
                   await Navigation.PushPopupAsync(new Page1());  
               }  
           }  
    

    Best Regards,

    Leon Lu


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.