我想在弹出页面中添加一个关闭按钮,但我希望它位于右上角,如下图所示:
我怎样才能像第一张图片一样塑造我的弹出窗口?
<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 & Yazdır" TextColor="Black" BackgroundColor="#4DC6C7" FontSize="Small" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand" />
</StackLayout>
</cardView:CardView.CardViewContent>
</cardView:CardView>
</StackLayout>
</ContentPage.Content>
将您的 XAML 更新为以下内容
<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 & 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>
导航到页面时,使用 PushModalAsync
await Navigation.PushModalAsync(new PopupView());