首页 > 解决方案 > xamarin 形式的背景

问题描述

我想为弹出窗口创建背景。

背景是指半透明背景,位于弹出窗口后面并在整个应用程序屏幕上延伸。这使得弹出窗口更加占主导地位,并阻止点击背景中其他任何内容的可能性。

如果可能的话,如果弹出窗口 xaml 代码位于视图结构的深处,那将是最好的。不在层次结构的顶部或底部。

我的问题是背景尺寸不会超过其父尺寸。

因此,如果我的视图是 1000x1000 我的视图内容是 500x500 并且我的弹出窗口在这个 500x500 中,它不会超过这个大小。

我尝试使用 Position absolute、relative、translatin x/y,将边距调整为高值以获得更大的尺寸。

我只是无法完成它。

例子 在此处输入图像描述

标签: xamlxamarinxamarin.forms

解决方案


您可以使用 Plugin PopupPage。并根据需要设置弹出窗口的布局

<?xml version="1.0" encoding="utf-8" ?>
<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="MyProject.MyPopupPage">
    <!--You can set an animation in the xaml file or in the csharp code behind-->
    <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-->
    <StackLayout 
        VerticalOptions="Center" 
        HorizontalOptions="Center" 
        Padding="20, 20, 20, 20">
        //...
    </StackLayout>
</pages:PopupPage>

有关更多详细信息,您可以查看https://github.com/rotorgames/Rg.Plugins.Popup/wiki/Getting-started


推荐阅读