【发布时间】:2019-02-09 02:10:30
【问题描述】:
我有一个要求,我需要在模式弹出页面中显示一个列表。我可以显示一个列表,但我不能使背景颜色透明或半透明,以便它下面的页面部分可见。
我正在使用以下方式从我的视图模型中推送页面:
NavigationParameters oNavParams = new NavigationParameters();
oNavParams.Add("Mode", "FeedBack");
oNavParams.Add("selectedItem", txtFeedback);
_navigationService.NavigateAsync("PopupBox", oNavParams);
这是我的 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>
这是我的代码:
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)
{
}
}
我也尝试过设置以下内容:
this.BackgroundColor= new Color(0, 0, 0, 0.4);
但它不起作用。有什么方法可以实现这一点?使用自定义渲染器或任何其他解决方法来显示模式。 我不想使用 Rg.Plugins.Popup,因为我遇到了问题。所以我正在寻找替代方案。请帮忙。
【问题讨论】:
标签: xamarin.forms custom-renderer modalpopup