Search code examples
xamarinbuttonxamarin.formspopup

Rg plugin PopUp Page Close button Xamarin forms


I want to add a close button to my popup pages but I want it top right corner like this image: enter image description here

That's my popup page : enter image description here

How can I shape my pop up like first image ?

 <ContentPage.Content>
    <StackLayout Margin="20"  HeightRequest="400"   VerticalOptions="Center"  HorizontalOptions="Center">

        <cardView:CardView
                            xct:CornerRadiusEffect.CornerRadius="16"
                            BackgroundColor="White"
                            CardViewHasShadow="True"
                            HorizontalOptions="Center"
                            VerticalOptions="Center" 
                            >
            <cardView:CardView.CardViewContent>
                
                <StackLayout Padding="10" HeightRequest="200" WidthRequest="300"  >

                    <ImageButton Source="@drawable/x.png" Command="{Binding CloseButtonCommand}"  BackgroundColor="Transparent" HorizontalOptions="End" WidthRequest="30" HeightRequest="30"/>
                    <Picker Title="Yazıcı Listesi" TitleColor="Black" HorizontalTextAlignment="Center" />

                    <Button Text="Kaydet &amp; Yazdır" TextColor="Black"  BackgroundColor="#4DC6C7" FontSize="Small" VerticalOptions="CenterAndExpand"  HorizontalOptions="CenterAndExpand" />


                </StackLayout>
            </cardView:CardView.CardViewContent>
        </cardView:CardView>


    </StackLayout>
</ContentPage.Content>

Solution

  • Update your XAML to below

    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 x:Class="Test.Views.PopupView"
                 BackgroundColor="#40000000">
        <ContentPage.Content>
            <StackLayout HeightRequest="400"   VerticalOptions="Center"  HorizontalOptions="Center">
                <Grid Margin="20">
                    <Frame CornerRadius="20" HasShadow="False">
                        <StackLayout Padding="10" HeightRequest="200" WidthRequest="300"  >
                            <Picker Title="Yazıcı Listesi" TitleColor="Black" HorizontalTextAlignment="Center" />
                            <Button Text="Kaydet &amp; Yazdır" TextColor="Black"  BackgroundColor="#4DC6C7" FontSize="Small" VerticalOptions="CenterAndExpand"  HorizontalOptions="CenterAndExpand" />
                        </StackLayout>
                    </Frame>
                    <ImageButton Margin="0,-10, -10,0" Source="x.png" Clicked="ImageButton_Clicked" BackgroundColor="Transparent" VerticalOptions="Start" HorizontalOptions="End" WidthRequest="30" HeightRequest="30"/>
                </Grid>
            </StackLayout>
        </ContentPage.Content>
    </ContentPage>
    

    While navigating to page, use PushModalAsync

    await Navigation.PushModalAsync(new PopupView());
    

    enter image description here