Xamarin Forms 内容页面使背景颜色透明

Deb*_*ish 1 custom-renderer modalpopup xamarin.forms

我有一个要求,我需要在模态弹出页面中显示一个列表。我可以显示一个列表,但我不能使背景颜色透明或半透明,以便它下面的页面部分可见。

我正在使用以下方法从我的视图模型推送页面:

NavigationParameters oNavParams = new NavigationParameters();
oNavParams.Add("Mode", "FeedBack");
oNavParams.Add("selectedItem", txtFeedback);
_navigationService.NavigateAsync("PopupBox", oNavParams);
Run Code Online (Sandbox Code Playgroud)

这是我的 xaml 代码:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
             xmlns:local="clr-namespace:MyApp"
             prism:ViewModelLocator.AutowireViewModel="True"
             x:Class="MyApp.Views.PopupBox">
    <ContentPage.Content>
        <AbsoluteLayout Padding="0" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
            <ContentView x:Name="popupListView" BackgroundColor="Transparent" Padding="10, 0" IsVisible="false" AbsoluteLayout.LayoutBounds="0, 0, 1, 1" AbsoluteLayout.LayoutFlags="All">
                <StackLayout VerticalOptions="Center" HorizontalOptions="Center">
                    <StackLayout Orientation="Vertical" HeightRequest="200" WidthRequest="300" BackgroundColor="White">
                        <ListView x:Name="sampleList">
                        </ListView>
                    </StackLayout>
                </StackLayout>
            </ContentView>
        </AbsoluteLayout>
    </ContentPage.Content>
</ContentPage>
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

  public PopupBox()
        {
            try
            {
                InitializeComponent();
                NavigationPage.SetHasNavigationBar(this, false);
                sampleList.ItemsSource = new List<string>
            {
                "Test ListView",
                "Test ListView",
                "Test ListView",
                "Test ListView",
                "Test ListView",
                "Test ListView",
                "Test ListView",
                "Test ListView",
                "Test ListView",
                "Test ListView",
                "Test ListView"
            };

                 popupListView.IsVisible = true;


            }
            catch (Exception ex)
            {

            }
            }
Run Code Online (Sandbox Code Playgroud)

这是输出: 在此处输入图片说明

我还尝试设置以下内容:

  this.BackgroundColor= new Color(0, 0, 0, 0.4);
Run Code Online (Sandbox Code Playgroud)

但它不起作用。有什么办法可以实现这一点?使用自定义渲染器或任何其他解决方法来显示模式。我不想使用 Rg.Plugins.Popup,因为我遇到了问题。所以我正在寻找替代方案。请帮忙。

Nic*_*sky 5

如果没有自定义渲染器,这将不起作用。今天获得所需的常用方法是简单地使用适用于 Xamarin 表单的弹出页面插件 ( https://github.com/rotorgames/Rg.Plugins.Popup ) nugetRg.Plugins.Popup可用。